The idea behind snapshot testing is that instead of manually checking an object or component for equality with hardcoded data, we can execute the toMatchSnapshot function. As a result, the snapshot file will be generated on disk under the __snapshots__ directory adjacent to your test. Snapshot file contains the structure of your tested component object or function.
If you later change the code and snapshot is different, then your test will fail, and you will need to manually update your snapshot or execute npm test -- -u to update all failing snapshots.
Let's refactor our routes test to use the snapshot testing feature:
it('has all needed routes', () => {
expect(routes).toMatchSnapshot();
});
Note that when running this test for the first time, snapshot will be generated under config/__tests__/__snapshots__/routes...