Skip to content
/ refute Public

[JavaScript] refute is "assert.not*" assertion library.

License

Notifications You must be signed in to change notification settings

azu/refute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

refute Build Status

refute is "assert.not*" assertion library.

It's inspired by busterjs/referee.

Installation

npm install --save-dev refute

Usage

refute inherit from assert(Node's Assert).

var assert = require("assert");
var refute = require("refute")(assert);

API

refute(false);
refute.equal = assert.notEqual.bind(assert);
refute.strictEqual = assert.notStrictEqual.bind(assert);
refute.deepEqual = assert.notDeepEqual.bind(assert);
refute.throws = assert.doesNotThrow.bind(assert);

Example

var assert = require("assert");
var refute = require("refute")(assert);
describe("refute-test", function () {
    it("refute", function () {
        refute(false);// not true is pass
    });
    it("refute.equal", function () {
        refute.equal("string", "non-string");// pass
    });
    it("refute.deepEqual", function () {
        var obj = {
            a: 1
        };
        var expected = {
            b: 1
        };
        refute.deepEqual(obj, expected);// pass
    });
    it("refute.throws", function () {
        refute.throws(function(){
            assert(true);
        });
    });
});

Integrated with power-assert

You can use refute with power-assert.

  1. Change require("assert") to require("power-assert")
- var assert = require("assert");
+ var assert = require("power-assert");
  1. Add refute.* methods to espower's options.patterns.
require('espower-loader')({

    // directory where match starts with
    cwd: process.cwd(),

    // glob pattern using minimatch module
    pattern: 'test/**/*.js',

    // options for espower module
    espowerOptions: {
        patterns: [
            "assert(value, [message])",
            "refute(value, [message])",
            "assert.ok(value, [message])",
            "assert.equal(actual, expected, [message])",
            "refute.equal(actual, expected, [message])",
            "assert.notEqual(actual, expected, [message])",
            "assert.strictEqual(actual, expected, [message])",
            "refute.strictEqual(actual, expected, [message])",
            "assert.notStrictEqual(actual, expected, [message])",
            "assert.deepEqual(actual, expected, [message])",
            "refute.deepEqual(actual, expected, [message])",
            "assert.notDeepEqual(actual, expected, [message])"
        ]
    }
});

See espower.config.js and mocha.opts of example.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

About

[JavaScript] refute is "assert.not*" assertion library.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published