Skip to content

Commit

Permalink
feat: Add new jest methods (#419)
Browse files Browse the repository at this point in the history
Closes #407

Co-authored-by: Sassan Haradji <sassan@zardalu.dev>
  • Loading branch information
sassanh and Sassan Haradji committed Dec 15, 2020
1 parent a3eba3a commit facf14c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/normalizeOptions.js
Expand Up @@ -21,6 +21,10 @@ const defaultTransformedFunctions = [
'jest.doMock',
'jest.dontMock',
'jest.setMock',
'jest.requireActual',
'jest.requireMock',

// Older Jest methods
'require.requireActual',
'require.requireMock',
];
Expand Down
26 changes: 17 additions & 9 deletions test/call.test.js
@@ -1,7 +1,6 @@
import { transform } from '@babel/core';
import plugin from '../src';


// all calls take a path as the first argument
const calls = [
'require',
Expand All @@ -13,6 +12,8 @@ const calls = [
'jest.doMock',
'jest.dontMock',
'jest.setMock',
'jest.requireActual',
'jest.requireMock',
'require.requireActual',
'require.requireMock',
];
Expand All @@ -21,22 +22,27 @@ describe('function and method calls', () => {
const transformerOpts = {
babelrc: false,
plugins: [
[plugin, {
root: './test/testproject/src',
alias: {
test: './test/testproject/test',
[
plugin,
{
root: './test/testproject/src',
alias: {
test: './test/testproject/test',
},
},
}],
],
],
};

calls.forEach((name) => {
calls.forEach(name => {
describe(name, () => {
it('should resolve the path based on the root config', () => {
const code = `${name}("components/Header/SubHeader", ...args);`;
const result = transform(code, transformerOpts);

expect(result.code).toBe(`${name}("./test/testproject/src/components/Header/SubHeader", ...args);`);
expect(result.code).toBe(
`${name}("./test/testproject/src/components/Header/SubHeader", ...args);`
);
});

it('should alias the path', () => {
Expand Down Expand Up @@ -94,7 +100,9 @@ describe('function and method calls', () => {
const code = 'require["resolve"]("components/Sidebar/Footer", ...args);';
const result = transform(code, transformerOpts);

expect(result.code).toBe('require["resolve"]("./test/testproject/src/components/Sidebar/Footer", ...args);');
expect(result.code).toBe(
'require["resolve"]("./test/testproject/src/components/Sidebar/Footer", ...args);'
);
});

it('should ignore the call if the method name is unknown', () => {
Expand Down

0 comments on commit facf14c

Please sign in to comment.