Add 'throws'/'notThrows' assertion to Ospec for error reporting (#2255)

* Ospec: added assertion that function does/doesnt throw error

* Ospec.throws passes npm test

* Ospec.throws: Address requested changes

* Ospec: message comparison support for .throws/.notthrows

Credit to @maranomynet, #2227
This commit is contained in:
Robin (Robert) Thomas 2018-11-21 14:46:34 -06:00 committed by Isiah Meadows
parent 22427db882
commit 0fd1bc9cae
4 changed files with 40 additions and 1 deletions

View file

@ -220,6 +220,8 @@ else window.o = m()
define("notEquals", "should not equal", function(a, b) {return a !== b})
define("deepEquals", "should deep equal", deepEqual)
define("notDeepEquals", "should not deep equal", function(a, b) {return !deepEqual(a, b)})
define("throws", "should throw a", throws)
define("notThrows", "should not throw a", function(a, b) {return !throws(a, b)})
function isArguments(a) {
if ("callee" in a) {
@ -260,6 +262,18 @@ else window.o = m()
}
return false
}
function throws(a, b){
try{
a()
}catch(e){
if(typeof b === "string"){
return (e.message === b)
}else{
return (e instanceof b)
}
}
return false
}
function isRunning() {return results != null}
function Assert(value) {