Commit df7b6de8 authored by Paul Slaughter's avatar Paul Slaughter

Fix fake date when called as function

- Apparently this just returns the toString
- Also updates tests to have `matchInlineSnapshot`
so that we're using a test oracle vs. Date.
parent d8658f3e
......@@ -15,7 +15,7 @@ export const createFakeDateClass = ctorDefault => {
apply: (target, thisArg, argArray) => {
const ctorArgs = argArray.length ? argArray : ctorDefault;
return RealDate(...ctorArgs);
return new RealDate(...ctorArgs).toString();
},
// We want to overwrite the default 'now', but only if it's not already mocked
get: (target, prop) => {
......
......@@ -13,13 +13,17 @@ describe('spec/helpers/fake_date', () => {
});
it('should use default args', () => {
expect(new FakeDate()).toEqual(new Date(...DEFAULT_ARGS));
expect(FakeDate()).toEqual(Date(...DEFAULT_ARGS));
expect(new FakeDate()).toMatchInlineSnapshot(`2020-07-06T00:00:00.000Z`);
});
it('should use default args when called as a function', () => {
expect(FakeDate()).toMatchInlineSnapshot(
`"Mon Jul 06 2020 00:00:00 GMT+0000 (Greenwich Mean Time)"`,
);
});
it('should have deterministic now()', () => {
expect(FakeDate.now()).not.toBe(Date.now());
expect(FakeDate.now()).toBe(new Date(...DEFAULT_ARGS).getTime());
expect(FakeDate.now()).toMatchInlineSnapshot(`1593993600000`);
});
it('should be instanceof Date', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment