errors.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
define([
"../errors/create",
"doh"
], function(create, doh){
var TestError = create("TestError", function(message, foo){
this.foo = foo;
});
var OtherError = create("OtherError", function(message, foo, bar){
this.bar = bar;
}, TestError, {
getBar: function(){
return this.bar;
}
});
var testError = new TestError("hello", "asdf"),
otherError = new OtherError("goodbye", "qwerty", "blah");
doh.register("tests.errors", [
{
name: "TestError",
runTest: function(t){
t.t(testError instanceof Error, "testError should be an instance of Error");
t.t(testError instanceof TestError, "testError should be an instance of TestError");
t.f(testError instanceof OtherError, "testError should not be an instance of OtherError");
t.f("getBar" in testError, "testError should not have a 'getBar' property");
t.is("hello", testError.message, "testError's message property should be 'hello'");
if((new Error()).stack){
t.t(!!testError.stack, "custom error should have stack set");
}
}
},
{
name: "OtherError",
runTest: function(t){
t.t(otherError instanceof Error, "otherError should be an instance of Error");
t.t(otherError instanceof TestError, "otherError should be an instance of TestError");
t.t(otherError instanceof OtherError, "otherError should be an instance of OtherError");
t.t("getBar" in otherError, "otherError should have a 'getBar' property");
t.f(otherError.hasOwnProperty("getBar"), "otherError should not have a 'getBar' own property");
t.is("blah", otherError.getBar(), "otherError should return 'blah' from getBar()");
t.is("goodbye", otherError.message, "otherError's message property should be 'goodbye'");
}
}
]);
});