This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
documentation in README, updated screenshot
- Loading branch information
1 parent
e73124b
commit acfc853
Showing
3 changed files
with
177 additions
and
28 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 |
---|---|---|
@@ -1,7 +1,156 @@ | ||
|
||
#It-Is# | ||
|
||
##a terse assertion DSL## | ||
a terse assertion DSL, inheriting from node's assert module, but enhanced with the power of functional programming & colours! | ||
|
||
# Basic Usage# | ||
|
||
var it = require('it-is') | ||
|
||
it(actual).equal(10) | ||
|
||
# High-level Usuage # | ||
|
||
`every` applies an assertion function to every item in a list. | ||
|
||
it(arrayOfNumbers) | ||
.every(it.typeof('number')) | ||
|
||
|
||
`has` applies assertion functions to leaves of a tree. | ||
|
||
it({a:1, b: 3}) | ||
.has({ | ||
a: it.typeof('number').notEqual(3) | ||
, b: it.equal(3) | ||
}) | ||
|
||
huh? | ||
|
||
if you call `it` with an argument `it(actual)` assertions chained will be applied immediately. | ||
|
||
it(actual).equal(expected) | ||
|
||
is that same as | ||
|
||
assert.equal(actual,expected) | ||
|
||
if you don't provide an argument, but just start chaining `it.equal(expected)`, it returns a function which makes that assertion. | ||
|
||
it.typeof('number').notEqual(unexpected) | ||
|
||
returns a function like this: | ||
|
||
function (actual){ | ||
assert.typeof(actual,'number') //not in node's assert. added in it-is | ||
assert.notEqual(actual,unexpected) | ||
} | ||
|
||
pass these functions into It-Is's every and has for terse assertion easyness! | ||
|
||
then glance at the error messages which are highlighted to show the exact point the assertion failed: | ||
|
||
<img src="https://github.com/dominictarr/it-is/raw/master/screenshot.png" border = "0"/> | ||
|
||
#Assertion Methods# | ||
|
||
node's assert module methods: | ||
|
||
`ok`,`equal`,`notEqual`,`deepEqual`,`notDeepEqual`,`strictEqual`,`notStrictEqual`,`throws`,`doesNotThrow`,`ifError` | ||
|
||
and also: | ||
|
||
##typeof## | ||
assert type, expected can be 'string', 'number', 'boolean', 'object', 'function', or 'undefined' | ||
|
||
it(actual).typeof(type) | ||
|
||
##instanceof## | ||
assert instanceof, expected should be a constructor function | ||
|
||
it(actual).instanceof(constructor) | ||
|
||
example: | ||
|
||
it([]).instanceof(Array) | ||
|
||
##primitive## | ||
assert is not an object or a function | ||
|
||
it(7).primitive() | ||
|
||
##complex## | ||
assert is an object or a function | ||
|
||
it({}).complex() | ||
|
||
##function## | ||
assert is a function | ||
|
||
|
||
it(function(){}).function() | ||
|
||
##matches## | ||
assert matches a regular expresson | ||
|
||
it(actual).matches(regex) | ||
|
||
example: | ||
|
||
it('asdf@asdf.com').matches(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/) | ||
|
||
##like## | ||
assert two strings match, but ignoring case, white space and whether quotes are " or '. (is configurable) | ||
|
||
it(actual).like(expected, options) | ||
|
||
options object is optional! but should be this format: | ||
|
||
{case: boolean,whitespace: boolean, quotes: boolean} | ||
|
||
##every## | ||
|
||
apply assertions to every item in an array | ||
|
||
it(array).every(assertion) | ||
|
||
example: | ||
|
||
it([1,2,3,4,5]).every(it.typeof('number').notEqual(0)) | ||
|
||
assertion is just a function | ||
|
||
it([ | ||
[1,1.0] | ||
, [1,1e0] | ||
, [1,7/7] | ||
]).every(function (line){ | ||
assert.equal(line[0],line[1]) | ||
}) | ||
##has## | ||
|
||
apply asssertions to properties of an object, checking that properties and actually there first. | ||
|
||
it(actual).has(properties) | ||
|
||
if a property is primitive, it's checked for equality. | ||
if a property is a function, it's called with actual's corrisponding property as the argument. | ||
|
||
example: | ||
|
||
it({ | ||
a: 1 | ||
, b: 2 | ||
, c: { x: true } | ||
, d: [1,2,3,4,5,true,'string'] | ||
}) | ||
.has({ | ||
a: it.notEqual(0) | ||
, b: 2 //values are treated like it.equal(value) | ||
, c: it.complex() | ||
, d: it.every(it.primitive()) | ||
}) | ||
|
||
|
||
enjoy! |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.