jestil
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.3 • Public • Published

    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

    Install

    npm i jestil

    DownloadsWeekly Downloads

    77

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    11.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • otiai10