Skip to content

Commit 6b4e306

Browse files
test(no-topromise): add coverage for zero imports
1 parent 06f5feb commit 6b4e306

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/rules/no-topromise.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,50 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
220220
],
221221
},
222222
),
223+
fromFixture(
224+
stripIndent`
225+
// no imports
226+
class Observable {
227+
toPromise() {
228+
return Promise.resolve("a");
229+
}
230+
}
231+
const a = new Observable();
232+
a.toPromise().then(value => console.log(value));
233+
~~~~~~~~~ [forbidden suggest 0 1]
234+
`,
235+
{
236+
suggestions: [
237+
{
238+
messageId: 'suggestLastValueFrom',
239+
output: stripIndent`
240+
// no imports
241+
import { lastValueFrom } from "rxjs";
242+
class Observable {
243+
toPromise() {
244+
return Promise.resolve("a");
245+
}
246+
}
247+
const a = new Observable();
248+
lastValueFrom(a).then(value => console.log(value));
249+
`,
250+
},
251+
{
252+
messageId: 'suggestFirstValueFrom',
253+
output: stripIndent`
254+
// no imports
255+
import { firstValueFrom } from "rxjs";
256+
class Observable {
257+
toPromise() {
258+
return Promise.resolve("a");
259+
}
260+
}
261+
const a = new Observable();
262+
firstValueFrom(a).then(value => console.log(value));
263+
`,
264+
},
265+
],
266+
},
267+
),
223268
],
224269
});

0 commit comments

Comments
 (0)