Skip to content

Commit 7efb90c

Browse files
test(throw-error): evaluate different function bodies
1 parent c3fa7c3 commit 7efb90c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/rules/throw-error.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ ruleTester({ types: true }).run('throw-error', throwErrorRule, {
3232
3333
const ob1 = throwError(() => new MyFailure("Boom!"));
3434
`,
35+
stripIndent`
36+
// arrow function return
37+
import { throwError } from "rxjs";
38+
39+
throwError(() => {
40+
return new Error("Boom!");
41+
});
42+
`,
43+
stripIndent`
44+
// function return
45+
import { throwError } from "rxjs";
46+
47+
throwError(function () {
48+
return new Error("Boom!");
49+
});
50+
`,
3551
stripIndent`
3652
// any
3753
import { throwError } from "rxjs";
@@ -103,6 +119,17 @@ ruleTester({ types: true }).run('throw-error', throwErrorRule, {
103119
{ code: "NOT_FOUND" }
104120
));
105121
`,
122+
stripIndent`
123+
// Object.assign arrow function return
124+
import { throwError } from "rxjs";
125+
126+
throwError(() => {
127+
return Object.assign(
128+
new Error("Not Found"),
129+
{ code: "NOT_FOUND" }
130+
);
131+
});
132+
`,
106133
stripIndent`
107134
// no signature
108135
// There will be no signature for callback and
@@ -219,5 +246,14 @@ ruleTester({ types: true }).run('throw-error', throwErrorRule, {
219246
~~~~~~~~~ [forbidden]
220247
`,
221248
),
249+
fromFixture(
250+
stripIndent`
251+
// Object.assign with non-Error
252+
import { throwError } from "rxjs";
253+
254+
throwError(() => Object.assign({ message: "Not Found" }, { code: "NOT_FOUND" }));
255+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [forbidden]
256+
`,
257+
),
222258
],
223259
});

0 commit comments

Comments
 (0)