0.0.3 • Published 3 years ago

jestil v0.0.3

Weekly downloads
15
License
MIT
Repository
github
Last release
3 years ago

jestil

jest test utils, mocking global Date, and other stuff.

JavaScript CI npm version npm download codecov Maintainability

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

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago