Skip to content

Commit

Permalink
Add mock variable name test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Wang committed Jun 20, 2018
1 parent 5e816ff commit 366cb5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions e2e/babel-plugin-jest-hoist/__test_modules__/f.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export default () => 'unmocked';
4 changes: 4 additions & 0 deletions e2e/babel-plugin-jest-hoist/__tests__/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ jest.dontMock('../__test_modules__/Mocked');
const myObject = {mock: () => {}};
myObject.mock('apple', 27);

// Variable names prefixed with `mock` (ignore case) should not throw as out-of-scope
const MockMethods = () => {};
jest.mock('../__test_modules__/f', () => MockMethods);

describe('babel-plugin-jest-hoist', () => {
it('does not throw during transform', () => {
const object = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ FUNCTIONS.mock = args => {
/^mock/i.test(name) ||
// Allow istanbul's coverage variable to pass.
/^(?:__)?cov/.test(name),
'The module factory of `jest.mock()` is not allowed to ' +
'The module factory of `jest.mock()` is not allowed to ' +

This comment has been minimized.

Copy link
@thymikee

thymikee Jun 20, 2018

Collaborator

fix the indentation 😅?

This comment has been minimized.

Copy link
@timwangdev

timwangdev Jun 20, 2018

Contributor

Done and added test.

'reference any out-of-scope variables.\n' +
'Invalid variable access: ' +
name +
Expand Down

0 comments on commit 366cb5b

Please sign in to comment.