@open-wc/semantic-dom-diff
Advanced tools
Comparing version 0.14.2 to 0.14.3
@@ -8,3 +8,5 @@ /// <reference types="chai" /> | ||
shadowDom: Assertion; | ||
notEqual(actual: Object, expected: Object, message?: string): void; | ||
equalSnapshot(options?: Object): Assertion; | ||
notEqualSnapshot(options?: Object): Assertion; | ||
} | ||
@@ -11,0 +13,0 @@ |
@@ -41,7 +41,12 @@ // @ts-nocheck | ||
/** Base HTML assertion for `assert` interface. */ | ||
const assertHtmlEquals = (actual, expected, options) => { | ||
const assertHtmlEquals = (actual, expected, options, negate = false) => { | ||
// use chai's built-in string comparison, log the updated snapshot on error | ||
new chai.Assertion(getDiffableHTML(actual, options)).to.equal( | ||
getDiffableHTML(expected, options), | ||
); | ||
const assertion = new chai.Assertion(getDiffableHTML(actual, options)); | ||
const expectedDiffableHTML = getDiffableHTML(expected, options); | ||
if (negate) { | ||
assertion.not.equal(expectedDiffableHTML); | ||
} else { | ||
assertion.equal(expectedDiffableHTML); | ||
} | ||
}; | ||
@@ -66,3 +71,3 @@ | ||
assertHtmlEquals(html, value, args[0]); | ||
assertHtmlEquals(html, value, args[0], utils.flag(this, 'negate')); | ||
} else { | ||
@@ -81,3 +86,3 @@ _super.apply(this, [value, ...args]); | ||
/** Base HTML snapshot assertion for `assert` interface. */ | ||
function assertHtmlEqualsSnapshot(actual, options) { | ||
function assertHtmlEqualsSnapshot(actual, options, negate = false) { | ||
const { index } = context; | ||
@@ -102,13 +107,16 @@ context.index += 1; | ||
snapshotState.set(path, index, html, 'html'); | ||
} else if (!snapshotState.match(html, getDiffableHTML(snapshot.code, options))) { | ||
/* istanbul ignore next */ | ||
throw new chai.AssertionError( | ||
`Received value does not match stored snapshot ${index}`, | ||
{ | ||
actual: html, | ||
expected: snapshot.code, | ||
showDiff: true, | ||
}, | ||
chai.util.flag(this, 'ssfi'), | ||
); | ||
} else { | ||
const isMatch = snapshotState.match(html, getDiffableHTML(snapshot.code, options)); | ||
if ((isMatch && negate) || (!isMatch && !negate)) { | ||
/* istanbul ignore next */ | ||
throw new chai.AssertionError( | ||
`Received value does not match stored snapshot ${index}`, | ||
{ | ||
actual: html, | ||
expected: snapshot.code, | ||
showDiff: true, | ||
}, | ||
chai.util.flag(this, 'ssfi'), | ||
); | ||
} | ||
} | ||
@@ -129,8 +137,10 @@ } | ||
} | ||
return assertHtmlEqualsSnapshot.call(this, html, options); | ||
return assertHtmlEqualsSnapshot.call(this, html, options, utils.flag(this, 'negate')); | ||
} | ||
utils.addMethod(chai.Assertion.prototype, 'equalSnapshot', equalSnapshot); | ||
utils.addMethod(chai.Assertion.prototype, 'notEqualSnapshot', equalSnapshot); | ||
utils.addMethod(chai.assert, 'equalSnapshot', assertHtmlEqualsSnapshot); | ||
utils.addMethod(chai.assert, 'notEqualSnapshot', assertHtmlEqualsSnapshot); | ||
chai.assert.dom = { | ||
@@ -140,5 +150,11 @@ equal(actualEl, expectedHTML, options) { | ||
}, | ||
notEqual(actualEl, expectedHTML, options) { | ||
return assertHtmlEquals.call(this, getDomHtml(actualEl), expectedHTML, options, true); | ||
}, | ||
equalSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, actualEl, options); | ||
}, | ||
notEqualSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, actualEl, options, true); | ||
}, | ||
}; | ||
@@ -149,5 +165,11 @@ chai.assert.lightDom = { | ||
}, | ||
notEqual(actualEl, expectedHTML, options) { | ||
return assertHtmlEquals.call(this, getLightDomHtml(actualEl), expectedHTML, options, true); | ||
}, | ||
equalSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, getLightDomHtml(actualEl), options); | ||
}, | ||
notEqualSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, getLightDomHtml(actualEl), options, true); | ||
}, | ||
}; | ||
@@ -158,6 +180,12 @@ chai.assert.shadowDom = { | ||
}, | ||
notEqual(actualEl, expectedHTML, options) { | ||
return assertHtmlEquals.call(this, getShadowDomHtml(actualEl), expectedHTML, options, true); | ||
}, | ||
equalSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, getShadowDomHtml(actualEl), options); | ||
}, | ||
notEqualSnapshot(actualEl, options) { | ||
return assertHtmlEqualsSnapshot.call(this, getShadowDomHtml(actualEl), options, true); | ||
}, | ||
}; | ||
}; |
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.14.3](https://github.com/open-wc/open-wc/compare/@open-wc/semantic-dom-diff@0.14.2...@open-wc/semantic-dom-diff@0.14.3) (2019-10-13) | ||
### Bug Fixes | ||
* **semantic-dom-diff:** support negate ([#848](https://github.com/open-wc/open-wc/issues/848)) ([2330424](https://github.com/open-wc/open-wc/commit/2330424)) | ||
## [0.14.2](https://github.com/open-wc/open-wc/compare/@open-wc/semantic-dom-diff@0.14.1...@open-wc/semantic-dom-diff@0.14.2) (2019-09-15) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@open-wc/semantic-dom-diff", | ||
"version": "0.14.2", | ||
"version": "0.14.3", | ||
"description": "To compare dom and shadow dom trees. Part of open-wc recommendations", | ||
@@ -30,3 +30,3 @@ "author": "open-wc", | ||
}, | ||
"gitHead": "b57f10dd010c35e1fa1a40365f90e5a7adf194f5" | ||
"gitHead": "974dfc632ee1155528be87966bb3fa8ae5fab58d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56476
558