Skip to content

Instantly share code, notes, and snippets.

@mateutek
Created June 18, 2019 19:40
Show Gist options
  • Save mateutek/b83c004c855a94d047a354aa5eee7f86 to your computer and use it in GitHub Desktop.
Save mateutek/b83c004c855a94d047a354aa5eee7f86 to your computer and use it in GitHub Desktop.
React + TS + Jest + Enzyme
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
roots: [
'<rootDir>/src/',
'<rootDir>/tests/',
],
testRegex: '(<rootDir>/tests/.*|(\\.|/)(test|spec))\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
verbose: true,
moduleDirectories: [
'node_modules',
],
testPathIgnorePatterns: [
'/node_modules/'
],
testEnvironmentOptions: {
resources: 'usable'
},
snapshotSerializers: [
'enzyme-to-json/serializer'
],
collectCoverageFrom: [
'<rootDir>/src/**/*.tsx'
],
coveragePathIgnorePatterns: [
'/node_modules/',
],
coverageDirectory: '<rootDir>/tests/__coverage__/',
setupTestFrameworkScriptFile: '<rootDir>/configs/setupTest.js',
globals: {
window: {},
'ts-jest': {
tsConfig: './tsconfig.json'
}
},
"moduleNameMapper": {
"^.+\\.(css|less|scss)$": "identity-obj-proxy",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/__mocks__/fileMock.js",
"^@app(.*)$": "<rootDir>/src/$1"
}
};
"scripts": {
"test": "jest --watch --coverage",
}
const Enzyme = require('enzyme');
const EnzymeAdapter = require('enzyme-adapter-react-16');
// Setup enzyme's react adapter
Enzyme.configure({
adapter: new EnzymeAdapter()
});
window.alert = (msg) => { console.log(msg); };
window.matchMedia = () => ({});
window.scrollTo = () => { };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment