diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..ed9f9cc --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +coverage \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..f433881 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,26 @@ +{ + "rules": { + "quotes": [2, "single"], + "strict": [2, "never"], + "eol-last": 0, + "no-use-before-define": 0, + "new-cap": [0, {"capIsNew": false}], + "no-unused-vars": [2, {"args": "none"}], + "no-alert": 0, + "no-shadow": 0, + "object-shorthand": 0, + "no-underscore-dangle": 0, + "curly": 0, + "no-empty": 0, + "no-unused-expressions": 0 + }, + "env": { + "browser": true, + "node": true, + "mocha": true, + "es6": true + }, + "globals": { + "expect": true + } +} \ No newline at end of file diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..5b58298 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,7 @@ +{ + "disallowEmptyBlocks": true, + "validateIndentation": "\t", + "excludeFiles": [ + "coverage/**" + ] +} \ No newline at end of file diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index 3091757..0000000 --- a/.jshintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -coverage \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 6cb4a49..0000000 --- a/.jshintrc +++ /dev/null @@ -1,29 +0,0 @@ -{ - "asi" : false, - "bitwise" : true, - "boss" : false, - "curly" : true, - "debug": false, - "devel": false, - "eqeqeq": true, - "evil": false, - "expr": true, - "forin": false, - "immed": true, - "latedef" : false, - "laxbreak": false, - "multistr": true, - "newcap": true, - "noarg": true, - "node" : true, - "noempty": false, - "nonew": true, - "onevar": false, - "plusplus": false, - "strict": false, - "sub": false, - "trailing" : true, - "undef": true, - "unused": "vars", - "browser": true -} diff --git a/README.md b/README.md index 6cda1fc..a1579e5 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,7 @@ to contain subset */ ``` +and with asset interface +```js +assert.containSubset({a: 1, b: 2}, {a: 1}); +``` diff --git a/lib/chai-subset.js b/lib/chai-subset.js index ef75b55..ddd8403 100644 --- a/lib/chai-subset.js +++ b/lib/chai-subset.js @@ -2,7 +2,7 @@ module.exports = function(chai, utils) { var Assertion = chai.Assertion; var assertionPrototype = Assertion.prototype; - Assertion.addChainableMethod('containSubset', function (expected) { + Assertion.addMethod('containSubset', function (expected) { var actual = utils.flag(this, 'object'); var showDiff = chai.config.showDiff; @@ -15,6 +15,10 @@ module.exports = function(chai, utils) { showDiff ); }); + + chai.assert.containSubset = function(val, exp, msg) { + new chai.Assertion(val, msg).to.be.containSubset(exp); + }; }; function compare(expected, actual) { diff --git a/package.json b/package.json index 0ec9ed0..a6af1cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chai-subset", - "version": "1.0.1", + "version": "1.1.0", "description": "Object properties matcher for Chai", "main": "lib/chai-subset.js", "scripts": { @@ -27,10 +27,12 @@ }, "homepage": "https://github.com/debitoor/chai-subset", "devDependencies": { - "chai": "^2.1.2", + "chai": "^3.2.0", "coveralls": "^2.11.3", "istanbul": "^0.3.17", + "jscs": "^1.13.1", "mocha": "^2.2.1", - "mocha-jshint": "^2.0.2" + "mocha-eslint": "^1.0.0", + "mocha-jscs": "^1.2.0" } } diff --git a/test/common.js b/test/common.js index dbceaba..9f14210 100644 --- a/test/common.js +++ b/test/common.js @@ -1,4 +1,4 @@ var chai = require('chai'); -var chaiSubset = require("../lib/chai-subset"); +var chaiSubset = require('../lib/chai-subset'); global.expect = chai.expect; chai.use(chaiSubset); \ No newline at end of file diff --git a/test/eslint.spec.js b/test/eslint.spec.js new file mode 100644 index 0000000..75761bf --- /dev/null +++ b/test/eslint.spec.js @@ -0,0 +1 @@ +require('mocha-eslint')(['lib', 'test']); \ No newline at end of file diff --git a/test/jscs.spec.js b/test/jscs.spec.js new file mode 100644 index 0000000..fe580c8 --- /dev/null +++ b/test/jscs.spec.js @@ -0,0 +1 @@ +require('mocha-jscs')(['lib', 'test']); \ No newline at end of file diff --git a/test/jshint.spec.js b/test/jshint.spec.js deleted file mode 100644 index 5cb07d7..0000000 --- a/test/jshint.spec.js +++ /dev/null @@ -1 +0,0 @@ -require('mocha-jshint')(); \ No newline at end of file diff --git a/test/unit/chai-subset.spec.js b/test/unit/chai-subset.spec.js index 36453fd..9fa6114 100644 --- a/test/unit/chai-subset.spec.js +++ b/test/unit/chai-subset.spec.js @@ -118,4 +118,11 @@ describe('circular objects', function() { ] }); }); +}); + +describe('assert style of test', function () { + it('should find subset', function () { + var assert = require('chai').assert; + assert.containSubset({a: 1, b: 2}, {a: 1}); + }); }); \ No newline at end of file