Unit testing a method that creates a JWT and returns Error: secretOrPrivateKey must have a value

I am trying to write a unit test for the method I wrote which generates a JWT. I am doing the following describe(‘returns a token’, function() { it(‘should return a token’, function() { …

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