--save-dev --save-exact react-test-renderer # Write tests. Jest finds: # …/__tests__/Todo-test.js # …/Todo.spec.js # …/Todo.test.js # Run the test watcher. npm test
import Todo from './Todo'; // or .. if test file is in __tests__ describe('Todo', () => { it('renders completed item', () => { const text = 'Modify a component'; expect(renderer.create( <Todo text={text} completed={true} onClick={jest.fn()} /> ).toJSON()).toMatchSnapshot(); }); });
jest-snapshot-improvements npm run eject Are you sure you want to eject? This action is permanent. [y/N] y git add --all git commit -m "eject from react-scripts 0.6.0" # A tag is optional. We’ll refer to this commit when we uneject. git tag eject-from-0.6.0
run all tests. # Because we have committed # the file we need to test. # By default, create-react-app runs tests # related to files changed since last commit.
added compared to the commit before you ejected? git diff eject-from-0.6.0~1 eject-from-0.6.0 --name-status # Remove 2 files and 2 subdirectories # that were added when you ejected. git rm .babelrc git rm .eslintrc git rm -r config/ git rm -r scripts/
modified file change since the commit when you ejected? git diff eject-from-0.6.0 HEAD -- package.json # - "jest": "15.1.1", # + "jest": "16.0.0", # Revert the modified file to the commit before you ejected. git checkout eject-from-0.6.0~1 -- package.json # Because you only upgraded Jest, didn’t tweak the ejected config, # edit package.json only to upgrade "react-scripts" to "0.7.0"