Skip to content

Commit

Permalink
Only do subset check for vnode.sel
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Oct 7, 2018
1 parent 3001dde commit 299cc7d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ export function assertLooksLike(
.split('\n')
.slice(5)
.filter(s => s.indexOf('No newline at end of file') === -1)
.filter(s => !(s.startsWith('-') && s.indexOf('WILDCARD') !== -1))
.map(s => !(s.startsWith('+') || s.startsWith('-')) ? ' ' + s : s)
.map(s => s.startsWith('-') ? 'expected: ' + s.slice(1) : s)
.map(s => s.startsWith('+') ? 'actual: ' + s.slice(1) : s)
.filter(
s =>
!(s.startsWith('-') && s.indexOf('WILDCARD') !== -1)
)
.map(
s =>
!(s.startsWith('+') || s.startsWith('-'))
? ' ' + s
: s
)
.map(
s => (s.startsWith('-') ? 'expected: ' + s.slice(1) : s)
)
.map(
s => (s.startsWith('+') ? 'actual: ' + s.slice(1) : s)
)
.join('\n') +
(longError
? '\n\n' +
Expand Down Expand Up @@ -89,7 +101,13 @@ export function assertLooksLike(
if (isObj(actual) && isWildcard(expected)) {
return;
} else if (isObj(actual) && isObj(expected)) {
if (actual.sel === expected.sel) {
const actualSels = (actual.sel || '').split(/\.|#/);
const expectedSels = (expected.sel || '').split(/\.|#/);
const isSubset = expectedSels.reduce(
(acc, curr) => acc && actualSels.indexOf(curr) !== -1,
true
);
if (isSubset) {
if (actual.text !== expected.text) {
throw new Error(e4(actual, expected));
}
Expand Down Expand Up @@ -146,7 +164,11 @@ export function assertLooksLike(

for (let j = 0; j < tries[i].length; j++) {
try {
assertLooksLike(actual.children[j], tries[i][j], longError);
assertLooksLike(
actual.children[j],
tries[i][j],
longError
);
} catch (e) {
lastError = e.message;
success = false;
Expand Down

0 comments on commit 299cc7d

Please sign in to comment.