Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 10 months ago. Improve this question
Tag: chai
Why does mocha chai should not prove identity for `return this`, if I use Proxy:get in the constructor?
I want to write a class, that deals with undefined properties. I also want to return this to be able to chain methods to create a domain specific language (DSL). I return a Proxy from the constructor, to handle undefined properties. Now when testing the instance, it does happen, that return this does not prove to be identical with the
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 Note: I am not using expect yet, and seeing if the method works in first place by logging the result of the method to the console And I receive the following error: Error: secretOrPrivateKey must have a value
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 them. This is my approach but I get AssertionError: expected [ Array(2) ] to have the same members as [ Array(2) ] Previously we used
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 have a good way to gain control over that object and create mocks of its methods to test the behavior of my function.
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
Chai test array of objects to “contain something like” an object submatch
Ok. I’ve tried to read other questions here but still didn’t find a straightforward answer. How can I assert a partial object match in an array using chai? Something like the following: Just to clarify, my intention is to get as close to the example provided as possible. to chain after the .be.an(‘array’) and to provide only the partial object
Chai expect: an array to contain an object with at least these properties and values
I’m trying to validate that an array of objects like this: contains at least one object with both { a: 1 } and { c: 3 }: I thought I could do this with chai-things, but I don’t know all the properties of the object to be able to use and contain.a.thing.with.property doesn’t work with multiple properties :/ What’s the