Update design_management/components/toolbar/index_spec.js to use mocked new Date()
Summary
(Existing in master)
When we don't use mocked system time making calls to 'new Date()' will result in non-deterministic behavior in unit tests. In particular this causes '6 hours ago' to appear locally, and '1 hours ago' to appear in the CI env in our Vue snapshots.
See:
Summary of all failing tests
FAIL ee/spec/frontend/design_management/components/toolbar/index_spec.js
● Design management toolbar component › renders design and updated data
expect(value).toMatchSnapshot()
Received value does not match stored snapshot "Design management toolbar component renders design and updated data 1".
- Snapshot
+ Received
@@ -20,9 +20,9 @@
</h2>
<small
class="text-secondary"
>
- Updated 6 hours ago by Test Name
+ Updated 1 hour ago by Test Name
</small>
</div>
</header>
44 | createComponent();
45 |
> 46 | expect(vm.element).toMatchSnapshot();
| ^
47 | });
48 |
49 | it('links back to designs list', () => {
at Object.toMatchSnapshot (ee/spec/frontend/design_management/components/toolbar/index_spec.js:46:24)
Snapshot Summary
› 1 snapshot failed from 1 test suite. Inspect your code changes or run `yarn run jest -u` to update them.
Steps to reproduce
- Run
yarn jestlocally - Suite may have failures due to diff in snapshot
- Update snapshot with
yarn run jest -u - Push changes. CI job will fail with consistent snapshot
What is the current bug behavior?
jest vue snapshots fail locally, but pass on CI
What is the expected correct behavior?
jest test suite should pass locally and in CI env.
Possible fixes
Mock new Date() and system time.
Edited by -