Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Overview

Common API used for an automated testing:

  • sinon (sinonjs.com) for spying/stubbing/mocking.
  • FakeTimers for timers manipulation, docs
  • chai (chaijs.com) for asserting with expect API enouraged and some plugins:
    • chai-as-promised - Promises support, docs.
    • chai-datetime - Dates support, docs.
    • chai-integer - assirting on Integer type, docs.
    • chai-url - URLs support, docs.
    • sinon-chai - integration with sinon, docs.
    • chai-string - various handly String assertions, docs.
    • chai-dom - DOM support, docs.
    • chai-like - Partial objects comparison, docs.

Usage example

const{ expect, sinon, FakeTimers }from'@majus/testing';describe('My tests',()=>{letclock;beforeEach(()=>{sinon.stub(console,'log');clock=FakeTimers.install();});afterEach(()=>{clock.uninstall();sinon.restore();});it('my test for integer',()=>{constresult=myIntFunc();expect(result).to.be.an('integer').and.to.be.least(0);});it('my test for promise',async()=>{constresult=myAsyncFunc();awaitexpect(result).eventually.to.be.fulfilled;});it('my test for date',()=>{constresult=myDateFunc();expect(result).to.be.a('date').and.beforeDate(newDate());});it('my test for date',()=>{constresult=myStringFunc();expect(result).to.be.a('string').and.startWith('[');});it('my test for objects',()=>{constresult=myObjectFunc();expect(result).to.be.an('object').and.be.like({a: 1});});it('my test for arrays',()=>{constresult=myArrayFunc();expect(result).to.be.an('array').and.be.like([{a: 1},{a: 2}]);});it('my test for sinon',()=>{myComplexFunc();expect(console.log).not.to.be.called;});it('my test for timers',()=>{letflag=false;setTimeout(()=>{flag=true;},10000);clock.tick(10000);expect(flag).to.be.true;});});

About

Common API used for an automated testing

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages