Skip to content

Commit

Permalink
feat: Add support for jest doMock and dontMock functions (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
tleunen committed Feb 4, 2017
1 parent 05e69ba commit 0bc01ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export default ({ types: t }) => {
'genMockFromModule',
'mock',
'unmock',
'doMock',
'dontMock',
];

if (!(
Expand Down
46 changes: 46 additions & 0 deletions test/jest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ describe('jest functions', () => {
});
});

describe('jest.doMock', () => {
it('should resolve the path based on the root config', () => {
const code = 'jest.doMock("c1", () => {});';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.doMock("./test/examples/components/c1", () => {});');
});

it('should alias the path', () => {
const code = 'jest.doMock("utils", () => {});';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.doMock("./src/mylib/subfolder/utils", () => {});');
});

it('should not change the path', () => {
const code = 'jest.doMock("./utils", () => {});';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.doMock("./utils", () => {});');
});
});

describe('jest.unmock', () => {
it('should resolve the path based on the root config', () => {
const code = 'jest.unmock("c1");';
Expand All @@ -64,6 +87,29 @@ describe('jest functions', () => {
});
});

describe('jest.dontMock', () => {
it('should resolve the path based on the root config', () => {
const code = 'jest.dontMock("c1");';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.dontMock("./test/examples/components/c1");');
});

it('should alias the path', () => {
const code = 'jest.dontMock("utils");';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.dontMock("./src/mylib/subfolder/utils");');
});

it('should not change the path', () => {
const code = 'jest.dontMock("./utils");';
const result = transform(code, transformerOpts);

expect(result.code).toBe('jest.dontMock("./utils");');
});
});

describe('jest.genMockFromModule', () => {
it('should resolve the path based on the root config', () => {
const code = 'jest.genMockFromModule("c1");';
Expand Down

0 comments on commit 0bc01ec

Please sign in to comment.