Common API used for an automated testing:
sinon(sinonjs.com) for spying/stubbing/mocking.FakeTimersfor timers manipulation, docschai(chaijs.com) for asserting withexpectAPI 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 withsinon, docs.chai-string- various handly String assertions, docs.chai-dom- DOM support, docs.chai-like- Partial objects comparison, docs.
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;});});