I am getting an error "createSpyObj requires a non-empty array" with running unit tests, which were executed perfectly before

Issue

I am working on an Angular frontend unit test for updating the Sonar report,

Chrome Headless 93.0.4577.63 (Windows 10) ERROR
  An error was thrown in afterAll
  createSpyObj requires a non-empty array or object of method names to create spies for thrown
Chrome Headless 93.0.4577.63 (Windows 10): Executed 994 of 1041 (skipped 20) ERROR (0 secs / 11.047 secs)
Chrome Headless 93.0.4577.63 (Windows 10) ERROR
  An error was thrown in afterAll
Chrome Headless 93.0.4577.63 (Windows 10): Executed 994 of 1041 (skipped 20) ERROR (16.566 secs / 11.047 secs)

This is the error log I am getting. Previously all the tests ran without any problem. After a few new tests were added in a different component suddenly this error popped up. Then I removed the new tests and the new component also. But I am still getting this error. But the tests are executing without any error on the Chrome headless browser that automatically opens. Why am I getting this ERROR

Solution

Look through the code base for jasmine.createSpyObj and ensure that the array is not empty.

// Make sure you don't see empty arrays like so when using jasmine.createSpyObj
// The array is supposed to be an array of strings of public methods
// you want to mock.

jasmine.createSpyObj([]);
jasmine.createSpyObj('SomeName', []);

Answered By – AliF50

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published