Compare arrays of Errors in Chai

I have a validator method that returns an array with Errors. I want to create a unit test that compares this errors, but I can’t use expect(fn).to.throw since I don’t throw the errors, just return …

Mocking methods of a JavaScript object created within a function

I’ve written a JavaScript function that creates an object from a require()’d library, and then uses it. That seems to be causing me trouble when I try to write tests for it because I don’t seem to …

Why do these sinon stubs resolve to undefined?

I’ve written a unit test for the following code and stubbed the browser methods (read: web-extension API) using Sinon (more specifically: sinon-chrome, a dated but still functioning library for my use case). The unit test: The tests fail due to both the stubbed methods returning undefined, but the Sinon docs state quite clearly that stub.resolves(value): Causes the stub to return a Promise which resolves to the provided value. When constructing the Promise, sinon uses the Promise.resolve method. You are responsible for providing a polyfill in environments which do not provide Promise. The Promise library can be overwritten using the usingPromise

Using sinon how do I stub or fake the property of a callback

Using sinon how do I stub/fake a return value for this.lastID in the db.run function. I can fake the callback using this code: But it will fail as this.lastID is undefined. How do I overcome this? Thanks! Answer You can use stub.callsArgOn() to pass in a context value that will used as this in the callback. You would stub it with something like: Here’s an example with some made up functions:

Using sinon to mock a date object

Here is my code: var startTime = new Date(startDateTime).toLocaleTimeString(“en-US”, options); I need to get that startTime in my unit test. From knowing unit testing in a java perspective, I would …