Jasmine JavaScript Testing - toBe vs toEqual

后端 未结 7 1721
不思量自难忘°
不思量自难忘° 2020-11-28 17:32

Let\'s say I have the following:

var myNumber = 5;
expect(myNumber).toBe(5);
expect(myNumber).toEqual(5);

Both of the above tests will pass

相关标签:
7条回答
  • 2020-11-28 18:31

    I think toEqual is checking deep equal, toBe is the same reference of 2 variable

      it('test me', () => {
        expect([] === []).toEqual(false) // true
        expect([] == []).toEqual(false) // true
    
        expect([]).toEqual([]); // true // deep check
        expect([]).toBe([]); // false
      })
    
    0 讨论(0)
提交回复
热议问题