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

Add new jest methods #419

Merged
merged 1 commit into from Dec 15, 2020
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
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