Skip to content

Commit

Permalink
task: Enable passing Date instance to setNow (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
scalvert authored Jul 2, 2020
1 parent ad3a0e8 commit 2000fd2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions addon-test-support/date.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DateService from 'ember-date-service/services/date';
import DateService from "ember-date-service/services/date";

/**
* @class FakeDateService
Expand All @@ -22,7 +22,9 @@ export default DateService.extend({
},

setNow(date = Date.now()) {
this._now = date;
this._now = date instanceof Date ? date.getTime() : date;

return this._now;
},

reset() {
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/fake-date-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ module('Unit | Service | fake date', function(hooks) {
assert.equal(this.fakeService.now(), now);
});

test('it can set date to specific date via Date object', function(assert) {
let date = new Date();
let now = this.fakeService.setNow(date);

assert.equal(typeof this.fakeService.now(), 'number');
assert.equal(this.fakeService.now(), now);
});

test('it can reset date that was previously set', function(assert) {
let done = assert.async();
let now = Date.now();
Expand Down

0 comments on commit 2000fd2

Please sign in to comment.