Jasmine.js comparing arrays

后端 未结 4 1847
灰色年华
灰色年华 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条回答
  •  萌比男神i
    2020-12-13 05:47

    You can compare an array like the below mentioned if the array has some values

    it('should check if the array are equal', function() {
            var mockArr = [1, 2, 3];
            expect(mockArr ).toEqual([1, 2, 3]);
     });
    

    But if the array that is returned from some function has more than 1 elements and all are zero then verify by using

    expect(mockArray[0]).toBe(0);
    

提交回复
热议问题