Created
June 18, 2019 19:40
-
-
Save mateutek/b83c004c855a94d047a354aa5eee7f86 to your computer and use it in GitHub Desktop.
React + TS + Jest + Enzyme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"test": "jest --watch --coverage", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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