Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefer-spy-on): do not change behavior of fixed instances #390

Merged
merged 1 commit into from Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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