I have a static method that needs to call an instance method for each element of the passed in array(of instances of the Person class).
How do I check if it was called for each element using chai spy?
Here's my code which doesn't work. I set a spy on the array itself, but clearly it is never called on the array and I have no idea how to make it spy on the elements themselves.
describe("greetAll(arr) is a static method", () => {
it("should invoke sayHello() method on all the items of the passed persons array", () => {
const spy = chai.spy.on(arrayOfPersons, 'sayHello');
Person.greetAll(arrayOfPersons);
expect(spy).to.have.been.called.exactly(2);
});
});