-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/1.0.1: Update deps; bump version number Convert files to Unix Line-endings; add .editorconfig Add some Mocha tests Add Travis-CI & NPM badges to readme. Add Travis file; remove spaces in readme.
- Loading branch information
Showing
8 changed files
with
241 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "0.10" | ||
|
||
script: | ||
npm run lint && npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,83 @@ | ||
# 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. | ||
|
||
```html | ||
<!-- Browser --> | ||
<script src="chai.js"></script> | ||
<script src="chai-checkmark.js"></script> | ||
``` | ||
```js | ||
// CommonJS | ||
var chai = require("chai"), | ||
plugin = require("chai-checkmark") | ||
chai.use(plugin) | ||
``` | ||
```js | ||
// AMD | ||
require(["chai", "chai-checkmark"], function(chai, plugin) { | ||
chai.use(plugin) | ||
}) | ||
``` | ||
|
||
## How to use | ||
|
||
```js | ||
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][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][pull] for | ||
details. | ||
|
||
[develop]: https://github.com/sirlancelot/chai-checkmark/tree/develop | ||
[rebase]: http://darwinweb.net/articles/the-case-for-git-rebase | ||
[pull]: http://gitready.com/advanced/2009/02/11/pull-with-rebase.html | ||
[Chai]: http://chaijs.com/ | ||
# Chai Checkmark [![][ci-develop]][travis-ci] [![][downloads]][npm] | ||
|
||
**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. | ||
|
||
```html | ||
<!-- Browser --> | ||
<script src="chai.js"></script> | ||
<script src="chai-checkmark.js"></script> | ||
``` | ||
```js | ||
// CommonJS | ||
var chai = require("chai"), | ||
plugin = require("chai-checkmark") | ||
chai.use(plugin) | ||
``` | ||
```js | ||
// AMD | ||
require(["chai", "chai-checkmark"], function(chai, plugin) { | ||
chai.use(plugin) | ||
}) | ||
``` | ||
|
||
## How to use | ||
|
||
```js | ||
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][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][pull] for | ||
details. | ||
|
||
[Chai]: http://chaijs.com/ | ||
[ci-develop]: https://img.shields.io/travis/sirlancelot/chai-checkmark/develop.svg?style=flat-square | ||
[ci-master]: https://img.shields.io/travis/sirlancelot/chai-checkmark/master.svg?style=flat-square | ||
[develop]: https://github.com/sirlancelot/chai-checkmark/tree/develop | ||
[downloads]: https://img.shields.io/npm/dm/chai-checkmark.svg?style=flat-square | ||
[npm]: https://www.npmjs.org/package/chai-checkmark | ||
[pull]: http://gitready.com/advanced/2009/02/11/pull-with-rebase.html | ||
[rebase]: http://darwinweb.net/articles/the-case-for-git-rebase | ||
[travis-ci]: https://travis-ci.org/sirlancelot/chai-checkmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
;(function(context, factory) { | ||
if (typeof require === "function" && | ||
typeof exports === "object" && | ||
typeof module === "object" | ||
) { | ||
module.exports = factory() | ||
} else { | ||
if (typeof define === "function" && | ||
typeof define.amd === "object" | ||
) { | ||
define(factory) | ||
} else { | ||
if (!context.chai) { | ||
throw new Error("chai-checkmark couldn't find Chai.") | ||
} | ||
context.chai.use(factory()) | ||
} | ||
} | ||
}(this, function() { | ||
"use strict"; | ||
var nextTick = this.setImmediate || setTimeout, | ||
noop = function() {} | ||
|
||
// Chai Plugin Definition | ||
return function chaiCheckmark(chai, util) { | ||
var Assertion = chai.Assertion, | ||
expect = chai.expect | ||
|
||
function check(done) { | ||
/*jshint validthis:true */ | ||
var total = util.flag(this, "object"), | ||
count = 0 | ||
expect(total).a("number").above(0, "Provide a count to check") | ||
if (done) { | ||
expect(done).a("function", "Provide a function for check") | ||
} | ||
|
||
function chain() { | ||
expect(count).below(total, | ||
"Target checkmarks already reached") | ||
count += 1; | ||
} | ||
function mark() { | ||
if (count === total && done) { nextTick(done, 0) } | ||
return noop; | ||
} | ||
mark.getCount = function() { return count; } | ||
|
||
Assertion.addChainableMethod("mark", mark, chain) | ||
return mark; | ||
} | ||
Assertion.addMethod("check", check) | ||
Assertion.addMethod("checks", check) | ||
} | ||
})) | ||
;(function(context, factory) { | ||
if (typeof require === "function" && | ||
typeof exports === "object" && | ||
typeof module === "object" | ||
) { | ||
module.exports = factory() | ||
} else { | ||
if (typeof define === "function" && | ||
typeof define.amd === "object" | ||
) { | ||
define(factory) | ||
} else { | ||
if (!context.chai) { | ||
throw new Error("chai-checkmark couldn't find Chai.") | ||
} | ||
context.chai.use(factory()) | ||
} | ||
} | ||
}(this, function() { | ||
"use strict"; | ||
var nextTick = (typeof setImmediate === "function" ? | ||
setImmediate : setTimeout), | ||
noop = function() {} | ||
|
||
// Chai Plugin Definition | ||
return function chaiCheckmark(chai, util) { | ||
var Assertion = chai.Assertion, | ||
expect = chai.expect | ||
|
||
function check(done) { | ||
/*jshint validthis:true */ | ||
var total = util.flag(this, "object"), | ||
count = 0 | ||
expect(total).a("number").above(0, "Provide a count to check") | ||
if (done) { | ||
expect(done).a("function", "Provide a function for check") | ||
} | ||
|
||
function chain() { | ||
expect(count).below(total, | ||
"Target checkmarks already reached") | ||
count += 1; | ||
} | ||
function mark() { | ||
if (count === total && done) { nextTick(done, 0) } | ||
return noop; | ||
} | ||
mark.getCount = function() { return count; } | ||
|
||
Assertion.addChainableMethod("mark", mark, chain) | ||
return mark; | ||
} | ||
Assertion.addMethod("check", check) | ||
Assertion.addMethod("checks", check) | ||
} | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
|
||
var chai = require("chai") | ||
var chaiCheckmark = require("../chai-checkmark") | ||
|
||
chai.should() | ||
chai.use(chaiCheckmark) | ||
|
||
global.chaiCheckmark = chaiCheckmark | ||
global.expect = chai.expect | ||
global.Assertion = chai.Assertion | ||
global.AssertionError = chai.AssertionError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--reporter spec | ||
--require test/bootstrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
/* global describe, it, expect, Assertion, AssertionError */ | ||
|
||
describe("Chai Checkmark", function() { | ||
it("should add a method to Assertion", function() { | ||
expect(Assertion).to.respondTo("check") | ||
expect(Assertion).to.respondTo("checks") | ||
}) | ||
|
||
describe("Assertion#Check()", function() { | ||
it("should return a function with methods", function() { | ||
var subject = expect(1).check() | ||
|
||
expect(subject).to.be.a("function") | ||
|
||
expect(subject).itself.to.respondTo("getCount") | ||
}) | ||
|
||
it("should accept only numbers greater than 0", function() { | ||
expect(subject(-1)).to.Throw(AssertionError) | ||
expect(subject(0)).to.Throw(AssertionError) | ||
expect(subject("wat")).to.Throw(AssertionError) | ||
expect(subject(NaN)).to.Throw(AssertionError) | ||
|
||
subject(1)() | ||
subject(10)() | ||
subject(100)() | ||
|
||
function subject(value) { | ||
return function() { | ||
return expect(value).check(); | ||
}; | ||
} | ||
}) | ||
|
||
it("should allow a callback function to be passed in", function() { | ||
expect(subject("wat")).to.Throw(AssertionError) | ||
|
||
subject(function() {})() | ||
|
||
function subject(callback) { | ||
return function() { | ||
return expect(1).check(callback); | ||
}; | ||
} | ||
}) | ||
}) | ||
|
||
describe("Assertion#Mark()", function() { | ||
it("should increment the count", function() { | ||
var mark = expect(2).checks() | ||
|
||
expect(mark.getCount()).to.equal(0).mark() | ||
expect(mark.getCount()).to.equal(1).mark() | ||
expect(mark.getCount()).to.equal(2) | ||
}) | ||
|
||
it("should throw an error if too many checks happened", function() { | ||
expect(1).check() | ||
|
||
subject() | ||
expect(subject).to.Throw(AssertionError) | ||
|
||
function subject() { | ||
return expect().mark(); | ||
} | ||
}) | ||
}) | ||
}) |