Jasmine JavaScript Testing - toBe vs toEqual

后端 未结 7 1752
不思量自难忘°
不思量自难忘° 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:21

    To quote the jasmine github project,

    expect(x).toEqual(y); compares objects or primitives x and y and passes if they are equivalent

    expect(x).toBe(y); compares objects or primitives x and y and passes if they are the same object

提交回复
热议问题