Skip to content

Instantly share code, notes, and snippets.

@RubenVerborgh
Last active December 10, 2015 18:58
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 RubenVerborgh/4478480 to your computer and use it in GitHub Desktop.
Save RubenVerborgh/4478480 to your computer and use it in GitHub Desktop.
Chai as Promised and Chai Things didn't work nicely together.
#!/usr/bin/env mocha --compilers coffee:coffee-script --reporter spec
(require "mocha-as-promised")()
chai = require "chai"
Q = require "q"
chai.should()
chai.use require "chai-as-promised"
chai.use require "chai-things"
array = [{ a: 1 }, { b: 2 }]
arrayPromise = Q.resolve(array)
# include these tests to see the expected error messages
includeFailingTests = off
describe "The array", ->
it "should be an array", ->
array.should.be.an("array") # (1)
it "should contain something deep equal to { a: 1 }", ->
array.should.contain.something.that.deep.equals({ a: 1 }) # (2)
if includeFailingTests
it "should contain something deep equal to { a: 2 }", ->
array.should.contain.something.that.deep.equals({ a: 2 }) # (3)
describe "The array promise", ->
it "should eventually be an array", ->
arrayPromise.should.eventually.be.an("array") # (4)
it "should eventually contain something deep equal to { a: 1 }", ->
arrayPromise.should.eventually.contain.something.that.deep.equals({ a: 1 }) # (5)
if includeFailingTests
it "should eventually contain something deep equal to { a: 2 }", ->
arrayPromise.should.eventually.contain.something.that.deep.equals({ a: 2 }) # (6)
@RubenVerborgh
Copy link
Author

In this example, we'd expect assertion (5) to pass, but it fails with

expected [ { a: 1 }, { b: 2 } ] to deeply equal { a: 1 }

This shows that Chai as Promised bypasses the something, since the message in case of failure should be

expected an element of [ { a: 1 }, { b: 2 } ] to deeply equal { a: 2 }

which can be seen by setting includeFailingTests to on.

@RubenVerborgh
Copy link
Author

The old version in which this problem occurred, has been updated to use a flag instead of a customized Assertion object, resolving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment