I am doing a unit test on a component that receive date as a variable. My test fails because the ate variable in the actual and expected object keeps adding few milliseconds to the date value.
describe('Clock',()=>{
it('works',()=>{
let renderer = createRenderer();
let date = new Date();
renderer.render(<Clock time={ date}> </Clock>);
let actualElement = renderer.getRenderOutput();
let expectedElement = <FormattedTime value={date} hour="numeric" minute="numeric" second="numeric" />;
expect(actualElement).toEqual(expectedElement);
});
});
When i run my test . IN the above, it shows the expectedElement date
added some few milliseconds.
- "value": [Date: 2016-01-28T04:48:57.000Z]
+ "value": [Date: 2016-01-28T04:48:57.893Z]
Please how do i make the date tally ? Or better get rid of the milli seconds . I tried many opetions like
let date = Math.floor(new Date().getTime()/1000);
let rTime = new Date(date * 1000);
renderer.render(<Clock time={ rTime}> </Clock>);
let actualElement = renderer.getRenderOutput();
let expectedElement = <FormattedTime value={rTime} hour="numeric" minute="numeric" second="numeric" />;
Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire