Skip to content

Commit d9a79b2

Browse files
chrisblossomSimenB
authored andcommitted
fix(prefer-spy-on): do not change behavior of fixed instances (#390)
Fixes #389
1 parent ce86d4a commit d9a79b2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/rules/__tests__/prefer-spy-on.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ruleTester.run('prefer-spy-on', rule, {
3131
type: AST_NODE_TYPES.AssignmentExpression,
3232
},
3333
],
34-
output: "jest.spyOn(obj, 'a'); const test = 10;",
34+
output: "jest.spyOn(obj, 'a').mockImplementation(); const test = 10;",
3535
},
3636
{
3737
code: "Date['now'] = jest['fn']()",
@@ -41,7 +41,7 @@ ruleTester.run('prefer-spy-on', rule, {
4141
type: AST_NODE_TYPES.AssignmentExpression,
4242
},
4343
],
44-
output: "jest.spyOn(Date, 'now')",
44+
output: "jest.spyOn(Date, 'now').mockImplementation()",
4545
},
4646
{
4747
code: 'window[`${name}`] = jest[`fn`]()',
@@ -51,7 +51,7 @@ ruleTester.run('prefer-spy-on', rule, {
5151
type: AST_NODE_TYPES.AssignmentExpression,
5252
},
5353
],
54-
output: 'jest.spyOn(window, `${name}`)',
54+
output: 'jest.spyOn(window, `${name}`).mockImplementation()',
5555
},
5656
{
5757
code: "obj['prop' + 1] = jest['fn']()",
@@ -61,7 +61,7 @@ ruleTester.run('prefer-spy-on', rule, {
6161
type: AST_NODE_TYPES.AssignmentExpression,
6262
},
6363
],
64-
output: "jest.spyOn(obj, 'prop' + 1)",
64+
output: "jest.spyOn(obj, 'prop' + 1).mockImplementation()",
6565
},
6666
{
6767
code: 'obj.one.two = jest.fn(); const test = 10;',
@@ -71,7 +71,8 @@ ruleTester.run('prefer-spy-on', rule, {
7171
type: AST_NODE_TYPES.AssignmentExpression,
7272
},
7373
],
74-
output: "jest.spyOn(obj.one, 'two'); const test = 10;",
74+
output:
75+
"jest.spyOn(obj.one, 'two').mockImplementation(); const test = 10;",
7576
},
7677
{
7778
code: 'obj.a = jest.fn(() => 10)',

src/rules/prefer-spy-on.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default createRule({
7979
const argSource = arg && context.getSourceCode().getText(arg);
8080
const mockImplementation = argSource
8181
? `.mockImplementation(${argSource})`
82-
: '';
82+
: '.mockImplementation()';
8383

8484
return [
8585
fixer.insertTextBefore(left, `jest.spyOn(`),

0 commit comments

Comments
 (0)