Expected [ ] to be [ ] Jasmine, how to check empty array

toBe doesn't check the contents of the array, it only checks if the references are the same.

expect([1]).toBe([1]) will fail because the references are different.

You should use toEqual, which has some smarts to check the array contents as opposed to just doing a reference comparison.


You can try like this -

expect(component.XYZ.length).toEqual(0);

Use toHaveSize matcher:

expect(array).toHaveSize(0);

It's strongly recommended to use because the error messages you get with it are much better (e.g. Error: Expected array to have size 0)

Coming with Jasmine 3.6: release docs