GithubHelp home page GithubHelp logo

chai-checkmark's Introduction

Chai Checkmark

Checkmark is a Chai plugin for counting assertions made during a test. Often, when dealing with asynchronous tests, it can be difficult to determine if a callback was actually called. With Checkmark, you can be assured that the assertion was made.

Installation

Include Checkmark in the browser, as a CommonJS module, or through AMD.

<!-- Browser -->
<script src="chai.js"></script>
<script src="chai-checkmark.js"></script>
// CommonJS
var chai = require("chai"),
    plugin = require("chai-checkmark")
chai.use(plugin)
// AMD
require(["chai", "chai-checkmark"], function(chai, plugin) {
    chai.use(plugin)
})

How to use

describe("something", function() {
  it("should check two things", function(next) {
    expect(2).checks(next) // <-- pass in the callback

    "sync test".should.be.a("string").mark() // <-- check 1

    setTimeout(function() {
      // check 2, callback is called after the current event finishes
      "async test".should.be.a("string").mark()
    }, 500)
  })
})

API

Checkmark builds on Chai's assertion library by adding just two methods:

expect(Number).check(Function) or .checks(Function)

This must be called before .mark() but doesn't have to be at the very beginning of a test. You establish how many times you expect .mark() to be called and optionally pass in a callback to be called when the number of marks is reached.

expect(str).to.be.a("string").mark()

Add .mark() to the end of every assertion to which you want to have tracked by Checkmark. You can use any number of Chai's assertions, including .and, as long as you end your statement with .mark().

Contributing

Pull Requests are welcome. They will only be merged if they are based off the tip of the develop branch. Please rebase (don't merge!) your changes if you are behind. To learn about why rebase is better than merge, check out The Case for Git Rebase.

In short, to bring your Working Copy up to the tip of develop, you can use the rebase feature: git pull --rebase. See Pull with Rebase for details.

chai-checkmark's People

Contributors

sirlancelot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

achingbrain

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.