Comparing version 1.0.0 to 1.1.0
@@ -1,28 +0,50 @@ | ||
var colors = require('colors/safe'), | ||
hiff = require('hiff'); | ||
var hiff = require('hiff'); | ||
module.exports = function(chai, utils) { | ||
var Assertion = chai.Assertion; | ||
function processChange(change) { | ||
return 'In node ' + change.before.parentPath + ':\n\t' + change.message; | ||
} | ||
Assertion.addChainableMethod('hiffEqual', function (expected) { | ||
var actual = this._obj; | ||
function obj(chaiContext) { | ||
return chaiContext._obj; // eslint-disable-line no-underscore-dangle | ||
} | ||
var result = hiff.compare(expected, actual); | ||
var changes = []; | ||
function createMethod(flag, hiffCheck) { | ||
return function getHiffMethod(_super) { | ||
return function hiffMethod() { | ||
var meth = flag(this, 'hiff') ? hiffCheck : _super; | ||
meth.apply(this, arguments); | ||
}; | ||
}; | ||
} | ||
if (result.different) { | ||
result.changes.map(function(change) { | ||
changes.push(colors.reset('\t') + 'In node ' + change.before.parentPath + ':\n\t' + change.message); | ||
}); | ||
} | ||
function hiffEqual(expected, options) { | ||
var actual = obj(this); | ||
var result = hiff.compare(expected, actual, options); | ||
var changes = result.different ? result.changes.map(processChange).join('\n') : ''; | ||
this.assert( | ||
!result.different, | ||
'expected html to match, but there were these changes: \n\n' + changes.join('\n'), | ||
'expected #{act} to not match #{exp}', | ||
expected, | ||
actual, | ||
true | ||
); | ||
}); | ||
this.assert( | ||
!result.different, | ||
'expected html to match, but there were these changes: \n\n' + changes, | ||
'expected #{act} to not match #{exp}', | ||
expected, | ||
actual, | ||
true | ||
); | ||
} | ||
module.exports = function chaiHiff(chai, utils) { | ||
var Assertion = chai.Assertion; | ||
var flag = utils.flag; | ||
var equal = createMethod(flag, hiffEqual); | ||
Assertion.addMethod('hiffEqual', hiffEqual); | ||
Assertion.addMethod('hiffEquals', hiffEqual); | ||
Assertion.addMethod('hiffEq', hiffEqual); | ||
Assertion.addProperty('hiff', function hiffProp() { | ||
flag(this, 'hiff', true); | ||
}); | ||
Assertion.overwriteMethod('equal', equal); | ||
Assertion.overwriteMethod('equals', equal); | ||
Assertion.overwriteMethod('eq', equal); | ||
}; |
{ | ||
"name": "chai-hiff", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "HTML matching assertions for Chai.js.", | ||
"main": "chai-hiff.js", | ||
"scripts": { | ||
"test": "mocha", | ||
"prepublish": "npm test && git diff --exit-code --quiet", | ||
"preversion": "npm test && git diff --exit-code --quiet", | ||
"test": "run-p mocha lint", | ||
"mocha": "mocha", | ||
"lint": "eslint .", | ||
"check-diff": "git diff --exit-code --quiet", | ||
"prepublish": "run-p test check-diff", | ||
"postversion": "git push && git push --tags" | ||
@@ -29,9 +31,12 @@ }, | ||
"dependencies": { | ||
"colors": "^1.1.2", | ||
"hiff": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.4.5" | ||
"chai": "^4.1.2", | ||
"eslint": "^4.11.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"mocha": "^4.0.1", | ||
"npm-run-all": "^4.1.2" | ||
} | ||
} |
@@ -16,4 +16,6 @@ Chai Hiff | ||
```javascript | ||
var chai = require('chai'); | ||
chai.use(require('chai-hiff')); | ||
import chai from 'chai'; | ||
import chaiHiff from 'chai-hiff'; | ||
chai.use(chaiHiff); | ||
``` | ||
@@ -31,1 +33,25 @@ | ||
``` | ||
### `.not.hiffEqual(expected)` | ||
Expect the `expected` to not equal the `actual`. | ||
```javascript | ||
expect('<html></html>').to.hiffEqual('<html></html>'); | ||
``` | ||
### `.hiff.equal(expected)` | ||
Expect the `expected` to equal the `actual`. | ||
```javascript | ||
expect('<html></html>').to.hiff.equal('<html></html>'); | ||
``` | ||
### `.not.hiff.equal(expected)` | ||
Expect the `expected` to not equal the `actual`. | ||
```javascript | ||
expect('<html></html>').to.not.hiff.equal('<html></html>'); | ||
``` |
@@ -1,16 +0,50 @@ | ||
var chai = require('chai'), | ||
expect = chai.expect; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
chai.use(require('../')); | ||
it('should match some differing but equivalent HTML', function () { | ||
expect(function () { | ||
describe('chai-hiff', function () { | ||
describe('.hiffEqual()', function () { | ||
it('should match some differing but equivalent HTML', function () { | ||
expect(function () { | ||
expect('<input name="my-input" value="stuff">').to.hiffEqual('<input value="stuff" name="my-input">'); | ||
}).not.to.throw(); | ||
}); | ||
}).not.to.throw(); | ||
}); | ||
it('should not match some non-equivalent HTML', function () { | ||
expect(function () { | ||
it('should not match some non-equivalent HTML', function () { | ||
expect(function () { | ||
expect('<input name="my-input" value="stuff">').to.hiffEqual('<div class="a-div"></div>'); | ||
}).to.throw('expected html to match, but there were these changes'); | ||
}).to.throw('expected html to match, but there were these changes'); | ||
}); | ||
}); | ||
describe('.hiff.equal()', function () { | ||
it('should match some differing but equivalent HTML', function () { | ||
expect(function () { | ||
expect('<input name="my-input" value="stuff">').to.hiff.equal('<input value="stuff" name="my-input">'); | ||
}).not.to.throw(); | ||
}); | ||
it('should not match some non-equivalent HTML', function () { | ||
expect(function () { | ||
expect('<input name="my-input" value="stuff">').to.hiff.equal('<div class="a-div"></div>'); | ||
}).to.throw('expected html to match, but there were these changes'); | ||
}); | ||
}); | ||
describe('.not.hiff.equal()', function () { | ||
it('should not match some differing but equivalent HTML', function () { | ||
var actual = '<input name="my-input" value="stuff">'; | ||
var expected = '<input name="my-input" value="stuff">'; | ||
expect(function () { | ||
expect(actual).not.to.hiff.equal(expected); | ||
}).to.throw("expected '" + actual + "' to not match '" + expected + "'"); | ||
}); | ||
it('should match some non-equivalent HTML', function () { | ||
expect(function () { | ||
expect('<input name="my-input" value="stuff">').not.to.hiff.equal('<div class="a-div"></div>'); | ||
}).not.to.throw(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
6677
1
8
97
56
6
- Removedcolors@^1.1.2
- Removedcolors@1.4.0(transitive)