We use airbnb's enzyme library to do snapshot tests with Jest.
When my snapshot tests are run by a developer in a different time zone, the tests fail because the other developer’s component will render an object’s date of creation with respect to THEIR time zone rather than mine. What is to be done?
const myCloudObject: CloudObject = {
uuid: '82e04b65-8b40-449e-8c0d-b7ba87bf814d',
name: 'myFile',
path: 'pgblu/myFile',
permissions: {Owner: ['Read', 'Write', 'Execute']},
owner: 'pgblu',
creationDate: new Date('2017-07-14 10:10:01.0'),
modificationDate: new Date('Mon Jul 24 08:05:47 CDT 2017'),
size: '200',
type: 'application'
}
The test:
import {shallow} from 'enzyme';
...
describe('Infobar', () => {
...
it('renders an Infobar component with one selection', () => {
const wrapper: ShallowWrapper = shallow(<Infobar selectedItems={[myCloudObject]} />);
const result: JSON = toJson(wrapper);
expect(result).toMatchSnapshot();
});
...});
The error report from my remote colleague:
● Infobar › renders an Infobar component with one selection
expect(value).toMatchSnapshot()
Received value does not match stored snapshot 1.
- Snapshot
+ Received
...
@@ -147,22 +147,22 @@
className="leftColumn">
Added
</span>
<span
className="mainColumn">
- Fri, Jul 14, 2017, 10:10:01 AM CDT
+ Fri, Jul 14, 2017, 10:10:01 AM GMT+2
</span>
</div>
<div
className="row">
<span
className="leftColumn">
Modified
</span>
<span
className="mainColumn">
- Mon, Jul 24, 2017, 8:05:47 AM CDT
+ Mon, Jul 24, 2017, 3:05:47 PM GMT+2
</span>
</div>
...