기본 유형 (예: 숫자, 부울, 문자열 등)의 경우에는 toBe와 toEqual 사이에 차이가 없다.
var a = { bar: 'baz' };
var b = { foo: a };
var c = { foo: a };
엄격한 비교 (===) 를 사용하면 일부 항목은 동일하다.
> b.foo.bar === c.foo.bar
true
> b.foo.bar === a.bar
true
> c.foo === b.foo
true
그러나 이들이 "equal" 이더라도 완전히 같지는 않다. 왜냐하면 그들은 다른 메모리 위치를 가졌기 때문이다.
> b === c
false
Jasmine의 toBe는 엄격한 동등성을 사용하며, 동일한 객체인지 확인한다. toEqual은 객체를 비교하고 동일한지 확인한다.
expect(b).not.toBe(c);
expect(b).toEqual(c);
reference https://stackoverflow.com/questions/22413009/jasmine-javascript-testing-tobe-vs-toequal
'Frontend > Jasmine' 카테고리의 다른 글
Difference of spyOn, callThrough, and callFake (0) | 2024.06.16 |
---|---|
Creating your calculator and Testing with Jasmine (2) | 2023.03.04 |
Why unit testing? why jasmine? (0) | 2023.03.01 |