Skip to content

Commit

Permalink
better handle 'undefined' expected/actual
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeseda committed Oct 10, 2023
1 parent 8385ae0 commit a13a1ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Binary file modified screen-shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/_make-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function ({ actual, expected }){
else d.value.forEach(v => output.push(` ${JSON.stringify(v)},`))
}

output.unshift('[')
output.unshift('Array [')
output.push(']')

return output
Expand All @@ -81,6 +81,8 @@ export default function ({ actual, expected }){
else output.push(d.value)
}

output[0] = `Object ${output[0]}`

return output.join('').split('\n')
}

Expand Down
12 changes: 7 additions & 5 deletions src/tap-arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default function createParser (options) {
P(`Expected: ${JSON.stringify(e)}`, indent)
}

if (actual === expected) { // shallow test output; can't be diffed
if (actual === 'undefined') actual = undefined
if (expected === 'undefined') expected = undefined

if (actual && expected && actual === expected) { // shallow test output; can't be diffed
P(`${_.expected('Expected')} did not match ${_.actual('actual')}.`, indent)
P(_.dim('TAP output cannot be diffed'), indent)
P(actual, indent)
Expand Down Expand Up @@ -139,15 +142,14 @@ export default function createParser (options) {
P(`Expected "${_.actual(actual)}" to not match ${_.expected(expected)}`, indent)
break
case 'throws':
// ? maybe don't handle different edges of "throws"
if (
actual
&& actual !== 'undefined'
&& typeof actual !== 'undefined'
&& expected
&& expected !== 'undefined'
&& typeof expected !== 'undefined'
) // this weird combination is throws with expected/assertion
P(`Expected ${_.expected(expected)} to match "${_.actual(actual.message || actual)}"`, indent)
else if (actual && actual !== 'undefined') // this combination is usually "doesNotThrow"
else if (actual && typeof actual !== 'undefined') // this combination is usually "doesNotThrow"
P(`Expected to not throw, received "${_.actual(actual)}"`, indent)
else
P('Expected to throw', indent)
Expand Down

0 comments on commit a13a1ac

Please sign in to comment.