]> git.ipfire.org Git - thirdparty/moment.git/commit
Fix Date mocking regression introduced in 2.11.0
authorNowell Strite <nowell@strite.org>
Mon, 4 Jan 2016 14:47:23 +0000 (09:47 -0500)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 9 Jan 2016 09:42:27 +0000 (11:42 +0200)
commite6fe681a2bee5f1c13f29d1c83f2ee698b60944e
tree39a6e7bfc40f9c3b77534442eb79e95768bc5ae4
parent5925ade194fa34e5bf2f56ebb26349295342f19a
Fix Date mocking regression introduced in 2.11.0

The commit https://github.com/moment/moment/commit/f54a32f4c62c12a710335211a73cb002a7249646 and the follow on refactoring https://github.com/moment/moment/commit/b1d686ed481e2211cb81a1c60eca850fcea93f21 broke the ability for Date mocking libraries ([MockDate](https://www.npmjs.com/package/mockdate), SinonJS, etc.) to mock out the Date object. I believe we should restore this functionality.

```js
const moment = require('moment'),
    mockdate = require('mockdate'),
    frozenTime = moment();

mockdate.set(frozenTime);
console.log('Frozen time: ', frozenTime.toISOString());

setTimeout(function() {
    console.log('Moment time: ', moment().toISOString());
}, 1000);
```

Running the code above will yield the following in `moment@2.10.6` and `moment@2.11.0` respectively.

```bash
$ node index.js
Frozen time:  2016-01-04T14:21:55.335Z
Moment time:  2016-01-04T14:21:55.335Z

$ node index.js
Frozen time:  2016-01-04T14:21:55.335Z
Moment time:  2016-01-04T14:21:56.355Z
```

- Fixes #2857
- Fixes #2855
src/lib/moment/now.js
src/test/moment/now.js