Skip to content

Commit

Permalink
fix: print undefined in the message, closes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 17, 2021
1 parent 9c8aea6 commit cc7a6c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions __tests__/serialize-test.ts
Expand Up @@ -62,3 +62,17 @@ describe('gives context to non-serializable objects', function() {
}).toThrowErrorMatchingSnapshot()
})
})

describe('null is different from undefined', function() {
const foo: any = function foo() {
const a = undefined
const b = null
lazyAss(a === b, a, '!==', b)
}

it('null in the message', function() {
expect(function() {
foo()
}).toThrowError(`undefined !== null`)
})
})
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -91,7 +91,7 @@
"pkgfiles": "pkgfiles",
"pretest": "npm run build",
"semantic-release": "semantic-release",
"size": "tarball=\"$(npm pack .)\"; wc -c \"${tarball}\"; tar tvf \"${tarball}\"; rm \"${tarball}\";",
"size": "npm pack --dry",
"test": "npm run unit && npm run jest",
"unit": "mocha test/commonjs.spec.js",
"jest": "jest",
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Expand Up @@ -45,6 +45,12 @@ function replacer(key, value) {
}

function toString(arg, k) {
if (arg === null) {
return 'null'
}
if (arg === undefined) {
return 'undefined'
}
if (isPrimitive(arg)) {
return JSON.stringify(arg)
}
Expand Down

0 comments on commit cc7a6c9

Please sign in to comment.