Jasmine.js comparing arrays

后端 未结 4 1849
灰色年华
灰色年华 2020-12-13 05:36

Is there a way in jasmine.js to check if two arrays are equal, for example:

arr = [1, 2, 3]
expect(arr).toBe([1, 2, 3])
expect(arr).toEqual([1, 2, 3])
         


        
4条回答
  •  旧巷少年郎
    2020-12-13 05:52

    Just did the test and it works with toEqual

    please find my test:

    http://jsfiddle.net/7q9N7/3/

    describe('toEqual', function() {
        it('passes if arrays are equal', function() {
            var arr = [1, 2, 3];
            expect(arr).toEqual([1, 2, 3]);
        });
    });
    

    Just for information:

    toBe() versus toEqual(): toEqual() checks equivalence. toBe(), on the other hand, makes sure that they're the exact same object.

提交回复
热议问题