jestil
v0.0.3
Published
jest utils
Downloads
119
Readme
jestil
jest test utils, mocking global Date
, and other stuff.
Example
Clock.freeze & release
import {Clock} from "jestil";
describe("Back to the Future", () => {
describe("DeLorean", () => {
it("can go back to the future", () => {
// Freeze the clock
const clock = Clock.freeze("1955-11-12 22:04:00");
// new Date().getFullYear() == 1955
expect(delorean.jump()).toBe(true);
// Release the clock
clock.release();
// new Date().getFullYear() == 2021 (maybe)
expect(delorean.jump()).toBe(false);
});
});
});
Fetch.replies
import {Fetch} from "jestil";
describe('SchrodingerCat', () => {
describe('exists', () => {
it('should return its existence', async () => {
// Define the response you want for any "fetch" call.
Fetch.replies({message: 'Hey, I must exist!', status: 200});
// Even it'll be called inside your method.
const response = await SchrodingerCat.askInsideBox();
// The response will be what you specified.
expect(response.message).toBe('Hey, I must exist!');
expect(response.status).toBe(200);
});
});
});
Issues
- https://github.com/otiai10/jestil/issues