Created
August 27, 2024 01:27
-
-
Save drazisil/3061f04e572fb8ee63ed279de33f3a9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throwme() { | |
const err = new Error("foo"); | |
err.cause = "bar"; | |
throw err; | |
}; | |
const expect = (fn) => { | |
const self = {}; | |
self.fn = fn; | |
let thrown = false | |
try { | |
self.res = self.fn.call(); | |
} catch (e) { | |
self.res = e; | |
self.thrown = true; | |
} | |
return { | |
toThrowWithCause: (c) => { | |
if (self.thrown !== true) { | |
throw new Error(`Expected ${self.fn} to throw, but it did not!`) | |
} | |
console.dir(Object.getOwnPropertyDescriptors(c)); | |
console.dir(Object.getOwnPropertyDescriptors(self.res)); | |
console.log('===========') | |
if (self.res instanceof Error && String(self.res.cause) === String(c)) { | |
return true; | |
} | |
throw new Error(`Expected ${String(c)}, recieved ${String(self.res.cause)}`) | |
} | |
} | |
}; | |
const expected = 'foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment