Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Last active November 25, 2016 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhartikainen/b1cf5af0f7a3fee384594b9bb1e325c5 to your computer and use it in GitHub Desktop.
Save jhartikainen/b1cf5af0f7a3fee384594b9bb1e325c5 to your computer and use it in GitHub Desktop.
Avoiding multiple asserts
//easy way to check if object has the expected "shape":
it('tests something', function() {
var expectedObject = {
some: 'prop',
values: 'here'
};
var result = doStuff();
assert.deepEqual(result, expectedObject);
});
//but if we want to check the object has some properties,
//where it might have more props than those, we can use...
assert(sinon.match(result).test(expectedObject))
//or alternatively, something like
//https://github.com/michelsalib/chai-shallow-deep-equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment