ember-mockdate-shim
v0.1.0
Published
ES6 accessible module for MockDate within your Ember application
Downloads
2,560
Readme
ember-mockdate-shim
ES6 accessible module for MockDate within your Ember applications.
Installation
ember install ember-mockdate-shim
Usage
MockDate's set
and reset
methods are renamed to freezeDateAt
and unfreezeDate
respectively.
import { freezeDateAt, unfreezeDate } from 'ember-mockdate-shim';
freezeDateAt(new Date('1/12/2017'));
unfreezeDate();
This is primarily useful for keeping the time data consistent between tests (ie: for visual diffs a la Percy). Any library methods that rely on new Date()
will return consistent outputs. For example: moment()
and faker.date.recent
You can use this in the beforeEach
and afterEach
hooks of your tests, or anywhere else you want to freeze the date at, how ever many times you want!
Please note that acceptance test support is only available in Ember >2.15.1 as that is when backburner.js
introduced the ability to make "now" configurable. More info here.
For use cases outside of tests, keep in mind that the shim is not included in production builds. See index.js for more info.
Running
ember serve
- Visit your app at http://localhost:4200.
Running Tests
yarn test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
Building
ember build
For more information on using ember-cli, visit https://ember-cli.com/.