Can be setup in package.json script test: jest --watchAll --verbose
--watchAll allows our code to be watched in the background and re run the tests when changes
classStack {constructor() {this.top =-1;this.items = {}; }getpeek() {returnthis.items[this.top]; }push(value) {this.top +=1;this.items[this.top] = value; }pop() {this.top -=1; }}// describe is used to define test suitedescribe('My Stack', () => {let stack;// jest has helper functions like beforeEach, afterEach, beforeAll, afterAllbeforeEach(() => { stack =newStack(); });// test/it function used for defining individual testsit('is created empty', () => {// toBe is a matcher which is used to match actual value with expected valueexpect(stack.top).toBe(-1);// toEqual matcher checks for value equality instead of object reference itselfexpect(stack.items).toEqual({}); });it('can push to the top', () => {stack.push(2)expect(stack.top).toBe(0)expect(stack.peek).toBe(2) });// it.todo used to pass test while you fix the issuesit('can pop off', () => {stack.push(2)stack.push(3)expect(stack.top).toBe(1)expect(stack.peek).toBe(3)stack.pop()expect(stack.top).toBe(0)expect(stack.peek).toBe(2) });})
Code Coverage
Tells us how much our tests cover our source code
We can add --coverage option in our package.json jest script section