Dittach Francois
Dittach Francois

Reputation: 23

Error: stub cannot call arg since it was not yet invoked

I'm encountering this error in one of my tests and I don't understand what it means in the context of Sinon.

I get that there is a problem with my stubs but what is "invoking" for Sinon?

Thanks

Upvotes: 1

Views: 1072

Answers (1)

Luis Pinto
Luis Pinto

Reputation: 91

Since you didn't provide any code, and since this has also happened to me, I'll answer with what worked in my context.

We were using the following code to test a callback in the controller:

serviceStub
    .withArgs(1, 2, sinon.match.func)
    .callArgWith(2, null);

// Call the controller for testing
controller(1, 2);

The problem here was the callArgWith function. This function is used to call a parameter when it has already been defined (which is not the case here, since the controller is only called after this definition).

In order to solve this the proper function to call is callsArgWith (with an s), which only calls the argument after it is defined.

--

Again I'm not sure if this was the problem you were having, but it evoques the same error and might help other people with the same issue.

Upvotes: 2

Related Questions