I'm trying to test React component which has imported SASS with jest using gulp task. The issue here is that gulp-jest doesn't map module names (so it can't skip .scss files) and test fails (throws: "SyntaxError: Unexpected token *"). I have no idea why it behaves this way.
The strangest thing is that is works perfectly via "npm test" and jest-cli, but doesn't with "gulp test" for some reason.
Here is the component:
import React from 'react';
import '../../scss/App.scss';
export default class App extends React.Component {
render() {
return (
<div className="main">
<h1>Here we go!</h1>
</div>
)
}
}
Here is the test:
import React from 'react';
import App from '../src/js/components/App';
describe('App', () => {
test('should be a React component', () => {
let instance = App.prototype instanceof React.Component;
expect(instance).toBe(true);
});
});
Here is the gulpfile:
var gulp = require('gulp');
var jest = require('gulp-jest').default;
gulp.task('test', () => {
process.env.NODE_ENV = 'test';
return gulp.src('test')
.pipe(jest({
config: {
"transformIgnorePatterns": [
"<rootDir>/dist/", "<rootDir>/node_modules/"
],
"automock": false,
"moduleNameMapper": {
"\\.scss$": "<rootDir>/jestignore.js"
}
}
}));
});
jestignore.js in the root directory just exports empty object.
I do have jest.config.js file exporting the exact configurations for npm test command (just wanted to simplify it for you by changing require() to config itself in the gulpfile).