CRIMX
CRIMX

Reputation: 99

Understanding Sinon.js's stub.yield()

stub.yield([arg1, arg2, ...])

Invoke callbacks passed to the stub with the given arguments. If the stub was never called with a function argument, yield throws an error. Also aliased as invokeCallback.

What does it mean "If the stub was never called with a function argument" ?

Upvotes: 1

Views: 1429

Answers (1)

mantoni
mantoni

Reputation: 1622

It means that if the stub was called, but there was no function in the given arguments, an exception is thrown.

Consider this stub:

sinon.stub(fs, 'readFile');

Now the test runs these lines:

fs.readFile('some-file'); // no callback passed
fs.readFile.yield(); // throws, because the stub was never invoked with a function

Upvotes: 1

Related Questions