Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elliot-nelson/mock-clock-js
An asynchronous mock clock library for javascript unit testing
https://github.com/elliot-nelson/mock-clock-js
jasmine javascript
Last synced: 24 days ago
JSON representation
An asynchronous mock clock library for javascript unit testing
- Host: GitHub
- URL: https://github.com/elliot-nelson/mock-clock-js
- Owner: elliot-nelson
- License: mit
- Created: 2017-05-13T15:08:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-16T13:00:55.000Z (over 7 years ago)
- Last Synced: 2024-09-30T07:43:24.010Z (about 1 month ago)
- Topics: jasmine, javascript
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mock-clock-js
An asynchronous mock clock library for javascript unit testing.
## Installation
npm install mock-clock --save-dev
## Usage
This library allows you to mock the clock in your Javascript unit tests, giving
you more control over the value of the current time and the behavior of timers.Unlike other implementations, ticking the clock is always an async operation. When
testing code that mixes Promises and timer behavior, it can be difficult (and
potentially undesirable) to truly flatten all behavior into a synchronous path.Let's jump into an example...
var clock = require('mock-clock');
describe('my tests', function () {
beforeEach(clock.install);
afterEach(clock.uninstall);it('runs something every 500ms', function (done) {
var frames = [];
setInterval(function () {
frames.push(true);
}, 500);expect(frames).toEqual([]);
clock.tick(499).then(function () {
expect(frames).toEqual([]);
return clock.tick(1);
}).then(function () {
expect(frames).toEqual([true]);
}).then(clock.ticks(500)).then(function () {
expect(frames).toEqual([true, true]);
done();
});
});
});### API
WIP
## License
Licensed under MIT. [Full license here »](LICENSE)
## Contributing
Pull requests are welcome. Make sure to include tests for any new or modified
functionality.Feature requests and issue reports are also welcome. When reporting an issue be
sure to include operating system, node version, and any other information
required to reproduce the problem.