Last active
April 8, 2017 07:14
-
-
Save rhostem/03a4eb41075403c943fc64b4b93fce15 to your computer and use it in GitHub Desktop.
Jest 설정. 웹팩을 사용하는 프로젝트의 경우 JS에 포함되는 파일의 mocking이 필요하다
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
// __mocks__/fileMock.js | |
module.exports = 'test-file-stub'; |
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
"jest": { | |
"transform": { | |
".*": "<rootDir>/node_modules/babel-jest" | |
}, | |
"unmockedModulePathPatterns": [ | |
"react", | |
"react-dom", | |
"react-addons-test-utils", | |
"fbjs", | |
"enzyme", | |
"chai", | |
"lodash", | |
"redux", | |
"react-redux", | |
"react-router" | |
], | |
"testEnvironment": "node", | |
"setupFiles": [ | |
"<rootDir>/client/test/test.setup.js" | |
], | |
"roots": [ | |
"<rootDir>/client" | |
], | |
"moduleFileExtensions": [ | |
"js", | |
"jsx" | |
], | |
"moduleNameMapper": { | |
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/client/test/fileMock.js", | |
"\\.(css|less)$": "<rootDir>/client/test/styleMock.js" | |
} | |
} |
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
// __mocks__/styleMock.js | |
module.exports = {}; |
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
/** | |
* Jest tutorial | |
* https://facebook.github.io/jest/docs/tutorial-react.html | |
* | |
* Redux - writing tests | |
* https://github.com/reactjs/redux/blob/master/docs/recipes/WritingTests.md | |
* | |
* enzyme basic usage | |
* https://github.com/airbnb/enzyme#basic-usage | |
* | |
* chai API reference | |
* http://chaijs.com/api/ | |
* | |
* chai-enzyme docs | |
* https://github.com/producthunt/chai-enzyme/blob/master/README.md | |
* | |
* chai-jsx docs | |
* https://github.com/ckknight/chai-jsx | |
*/ | |
import chai from 'chai'; | |
import chaiEnzyme from 'chai-enzyme'; | |
import chaiJsx from 'chai-jsx'; | |
import { jsdom } from 'jsdom'; | |
chai.use(chaiEnzyme()); | |
chai.use(chaiJsx); | |
var exposedProperties = ['window', 'navigator', 'document']; | |
global.document = jsdom(''); | |
global.window = document.defaultView; | |
Object.keys(document.defaultView).forEach((property) => { | |
if (typeof global[property] === 'undefined') { | |
exposedProperties.push(property); | |
global[property] = document.defaultView[property]; | |
} | |
}); | |
global.navigator = { | |
userAgent: 'node.js' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment