Skip to content

maxnordlund/chai-and-then

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chai-and-then

A simple helper for multiple async assertions. It allows for easy and natural chaining of your assertions, for example to observe side effects.

Instead of using this you would need to use .then, which can make the code harder to read.

Installation

Install it using npm.

npm install --save-dev chai-and-then

Then tell chai use it.

chai.use(require("chai-and-then"))
chai.use(require("chai-as-promised"))

This is important to add chai-as-promised last to make it pickup all assertions, this is true for not just this plugin.

Example

This is taken from the tests and shows how easy it is to observe side effects.

describe("a small example", function exampleTest() {
  it("correctly observers side effects", function sideEffects() {
    var target = { count : 0 }

    function foo() {
      target.count++
      return true
    }

    expect(target).to.have.property("count", 0)
    return expect(Promise.resolve().then(foo)).to.become(true)
      .andThen(target).to.have.property("count", 1)
  })
})

About

A simple chai helper for multiple async assertions

Resources

License

Stars

Watchers

Forks

Packages

No packages published