Skip to content

Commit 0bc01ec

Browse files
authored
feat: Add support for jest doMock and dontMock functions (#114)
1 parent 05e69ba commit 0bc01ec

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export default ({ types: t }) => {
7878
'genMockFromModule',
7979
'mock',
8080
'unmock',
81+
'doMock',
82+
'dontMock',
8183
];
8284

8385
if (!(

test/jest.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ describe('jest functions', () => {
4141
});
4242
});
4343

44+
describe('jest.doMock', () => {
45+
it('should resolve the path based on the root config', () => {
46+
const code = 'jest.doMock("c1", () => {});';
47+
const result = transform(code, transformerOpts);
48+
49+
expect(result.code).toBe('jest.doMock("./test/examples/components/c1", () => {});');
50+
});
51+
52+
it('should alias the path', () => {
53+
const code = 'jest.doMock("utils", () => {});';
54+
const result = transform(code, transformerOpts);
55+
56+
expect(result.code).toBe('jest.doMock("./src/mylib/subfolder/utils", () => {});');
57+
});
58+
59+
it('should not change the path', () => {
60+
const code = 'jest.doMock("./utils", () => {});';
61+
const result = transform(code, transformerOpts);
62+
63+
expect(result.code).toBe('jest.doMock("./utils", () => {});');
64+
});
65+
});
66+
4467
describe('jest.unmock', () => {
4568
it('should resolve the path based on the root config', () => {
4669
const code = 'jest.unmock("c1");';
@@ -64,6 +87,29 @@ describe('jest functions', () => {
6487
});
6588
});
6689

90+
describe('jest.dontMock', () => {
91+
it('should resolve the path based on the root config', () => {
92+
const code = 'jest.dontMock("c1");';
93+
const result = transform(code, transformerOpts);
94+
95+
expect(result.code).toBe('jest.dontMock("./test/examples/components/c1");');
96+
});
97+
98+
it('should alias the path', () => {
99+
const code = 'jest.dontMock("utils");';
100+
const result = transform(code, transformerOpts);
101+
102+
expect(result.code).toBe('jest.dontMock("./src/mylib/subfolder/utils");');
103+
});
104+
105+
it('should not change the path', () => {
106+
const code = 'jest.dontMock("./utils");';
107+
const result = transform(code, transformerOpts);
108+
109+
expect(result.code).toBe('jest.dontMock("./utils");');
110+
});
111+
});
112+
67113
describe('jest.genMockFromModule', () => {
68114
it('should resolve the path based on the root config', () => {
69115
const code = 'jest.genMockFromModule("c1");';

0 commit comments

Comments
 (0)