Toby Eggitt
Toby Eggitt

Reputation: 1872

Jasmine spy "expect(xxx).notToHaveBeenCalled()

With great thanks to those that so swiftly rescued me. The essence of the problem was that I failed to realize I should be looking in documentation for "matchers", and looking in "expect" was not going to solve my problem.

I'm working with Jasmine 3.0 (and very new to it!) and trying to verify that a spy sees zero calls to a target under particular conditions. I thought I might use the count() behavior for this, but I'm struggling to work out what syntax I should use.

I've tried

spyOn(target, 'action').and.callThrough();
target.triggeringAction();
expect(target.action).count().toBe(0);

But Jasmine reports TypeError: expect(...).count is not a function. I don't see any expect(...).toNotHaveBeenCalled() and I'm not sure where to look next.

Upvotes: 2

Views: 552

Answers (2)

Imran Panjwani
Imran Panjwani

Reputation: 156

This could work as well expect(target.action).not.toHaveBeenCalled();

Upvotes: 1

Kirill Simonov
Kirill Simonov

Reputation: 8491

You could use expect(target.action).toHaveBeenCalledTimes(0);

Upvotes: 3

Related Questions