Skip to content

Commit 4c0ae5a

Browse files
fix(prefer-spy-on): pass an implementation to mockImplementation in the fix (#982)
1 parent a6acf78 commit 4c0ae5a

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎src/rules/prefer-spy-on.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const getAutoFixMockImplementation = (
5555

5656
return argSource
5757
? `.mockImplementation(${argSource})`
58-
: '.mockImplementation()'
58+
: '.mockImplementation(() => undefined)'
5959
}
6060

6161
export default createEslintRule<Options, MESSAGE_IDS>({

‎tests/prefer-spy-on.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ ruleTester.run(rule.name, rule, {
1818
invalid: [
1919
{
2020
code: 'obj.a = vi.fn(); const test = 10;',
21-
output: "vi.spyOn(obj, 'a').mockImplementation(); const test = 10;",
21+
output:
22+
"vi.spyOn(obj, 'a').mockImplementation(() => undefined); const test = 10;",
2223
errors: [
2324
{
2425
messageId: 'useViSpayOn',
@@ -28,7 +29,7 @@ ruleTester.run(rule.name, rule, {
2829
},
2930
{
3031
code: "Date['now'] = vi['fn']()",
31-
output: "vi.spyOn(Date, 'now').mockImplementation()",
32+
output: "vi.spyOn(Date, 'now').mockImplementation(() => undefined)",
3233
errors: [
3334
{
3435
messageId: 'useViSpayOn',
@@ -39,7 +40,7 @@ ruleTester.run(rule.name, rule, {
3940
{
4041
code: 'window[`${name}`] = vi[`fn`]()',
4142

42-
output: 'vi.spyOn(window, `${name}`).mockImplementation()',
43+
output: 'vi.spyOn(window, `${name}`).mockImplementation(() => undefined)',
4344
errors: [
4445
{
4546
messageId: 'useViSpayOn',
@@ -49,7 +50,7 @@ ruleTester.run(rule.name, rule, {
4950
},
5051
{
5152
code: "obj['prop' + 1] = vi['fn']()",
52-
output: "vi.spyOn(obj, 'prop' + 1).mockImplementation()",
53+
output: "vi.spyOn(obj, 'prop' + 1).mockImplementation(() => undefined)",
5354
errors: [
5455
{
5556
messageId: 'useViSpayOn',
@@ -59,7 +60,8 @@ ruleTester.run(rule.name, rule, {
5960
},
6061
{
6162
code: 'obj.one.two = vi.fn(); const test = 10;',
62-
output: "vi.spyOn(obj.one, 'two').mockImplementation(); const test = 10;",
63+
output:
64+
"vi.spyOn(obj.one, 'two').mockImplementation(() => undefined); const test = 10;",
6365
errors: [
6466
{
6567
messageId: 'useViSpayOn',
@@ -103,7 +105,7 @@ ruleTester.run(rule.name, rule, {
103105
{
104106
code: 'foo[bar] = vi.fn().mockReturnValue(undefined)',
105107
output:
106-
'vi.spyOn(foo, bar).mockImplementation().mockReturnValue(undefined)',
108+
'vi.spyOn(foo, bar).mockImplementation(() => undefined).mockReturnValue(undefined)',
107109
errors: [
108110
{
109111
messageId: 'useViSpayOn',

0 commit comments

Comments
 (0)