Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(prefer-spy-on): do not change behavior of fixed instances (#390)
Fixes #389
  • Loading branch information
chrisblossom authored and SimenB committed Aug 12, 2019
1 parent ce86d4a commit d9a79b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/rules/__tests__/prefer-spy-on.test.ts
Expand Up @@ -31,7 +31,7 @@ ruleTester.run('prefer-spy-on', rule, {
type: AST_NODE_TYPES.AssignmentExpression,
},
],
output: "jest.spyOn(obj, 'a'); const test = 10;",
output: "jest.spyOn(obj, 'a').mockImplementation(); const test = 10;",
},
{
code: "Date['now'] = jest['fn']()",
Expand All @@ -41,7 +41,7 @@ ruleTester.run('prefer-spy-on', rule, {
type: AST_NODE_TYPES.AssignmentExpression,
},
],
output: "jest.spyOn(Date, 'now')",
output: "jest.spyOn(Date, 'now').mockImplementation()",
},
{
code: 'window[`${name}`] = jest[`fn`]()',
Expand All @@ -51,7 +51,7 @@ ruleTester.run('prefer-spy-on', rule, {
type: AST_NODE_TYPES.AssignmentExpression,
},
],
output: 'jest.spyOn(window, `${name}`)',
output: 'jest.spyOn(window, `${name}`).mockImplementation()',
},
{
code: "obj['prop' + 1] = jest['fn']()",
Expand All @@ -61,7 +61,7 @@ ruleTester.run('prefer-spy-on', rule, {
type: AST_NODE_TYPES.AssignmentExpression,
},
],
output: "jest.spyOn(obj, 'prop' + 1)",
output: "jest.spyOn(obj, 'prop' + 1).mockImplementation()",
},
{
code: 'obj.one.two = jest.fn(); const test = 10;',
Expand All @@ -71,7 +71,8 @@ ruleTester.run('prefer-spy-on', rule, {
type: AST_NODE_TYPES.AssignmentExpression,
},
],
output: "jest.spyOn(obj.one, 'two'); const test = 10;",
output:
"jest.spyOn(obj.one, 'two').mockImplementation(); const test = 10;",
},
{
code: 'obj.a = jest.fn(() => 10)',
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-spy-on.ts
Expand Up @@ -79,7 +79,7 @@ export default createRule({
const argSource = arg && context.getSourceCode().getText(arg);
const mockImplementation = argSource
? `.mockImplementation(${argSource})`
: '';
: '.mockImplementation()';

return [
fixer.insertTextBefore(left, `jest.spyOn(`),
Expand Down

0 comments on commit d9a79b2

Please sign in to comment.