Skip to content

Commit

Permalink
Merge pull request #2 from e-conomic/0.2
Browse files Browse the repository at this point in the history
Use chai.use for adding method
  • Loading branch information
eagleeye committed Aug 1, 2014
2 parents 6a1844c + a74b6c2 commit 49498a2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,40 @@ chai-subset [![Build Status](https://travis-ci.org/e-conomic/chai-subset.svg?bra

"containSubset" object properties matcher for Chai

Installation
===========

`npm install --save-dev chai-subset`

Usage
=====

common.js
```js
require('chai-subset').addMethods(chai);
var chai = require('chai');
var chaiSubset = require('chai-subset');
chai.use(chaiSubset);
```

spec.js
```js
var obj = {
a: 'b',
c: 'd',
e: {
foo: 'bar',
baz: {
qux: 'quux'
}
a: 'b',
c: 'd',
e: {
foo: 'bar',
baz: {
qux: 'quux'
}
};
}
};

expect(obj).to.containSubset({
e: {
foo: 'bar',
baz: {
qux: 'quux'
}
}
});
e: {
foo: 'bar',
baz: {
qux: 'quux'
}
}
});
```
10 changes: 2 additions & 8 deletions lib/chai-subset.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
module.exports =
{
compare:compare,
addMethods:addMethod
};

function addMethod(chai) {
module.exports = function(chai) {
chai.Assertion.addChainableMethod('containSubset', function (expected) {
var actual = this.__flags.object;
var msg = "\n" + JSON.stringify(actual, null, "\t") + "\n";
Expand All @@ -15,7 +9,7 @@ function addMethod(chai) {
expected
);
});
}
};

function compare(expected, actual) {
if (typeof(actual) !== typeof(expected)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chai-subset",
"version": "0.1.3",
"version": "0.2.0",
"description": "Object properties matcher for Chai",
"main": "lib/chai-subset.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var chai = require('chai');
var containSubset = require("../lib/chai-subset");
var chaiSubset = require("../lib/chai-subset");
global.expect = chai.expect;
containSubset.addMethods(chai);
chai.use(chaiSubset);

0 comments on commit 49498a2

Please sign in to comment.