-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from sinonjs/error-properties
Set code, actual and expected properties on errors
- Loading branch information
Showing
26 changed files
with
1,273 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Demo error messages and diff rendering with Mocha. | ||
*/ | ||
"use strict"; | ||
|
||
var assert = require("..").assert; | ||
|
||
describe("diff", function() { | ||
it("multiline string", function() { | ||
assert.equals("foo\nbar\ndoo\n", "bar\ndoo\nxyz\n"); | ||
}); | ||
|
||
it("objects", function() { | ||
assert.equals({ foo: 42 }, { foo: 66 }); | ||
}); | ||
|
||
it("matchJson", function() { | ||
assert.matchJson('{"foo":42,"bar":true}', { foo: 42, bar: false }); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
"use strict"; | ||
|
||
var actualAndTypeOfMessageValues = require("../actual-and-type-of-message-values"); | ||
|
||
module.exports = function(referee) { | ||
referee.add("isBoolean", { | ||
assert: function(actual) { | ||
return typeof actual === "boolean"; | ||
}, | ||
assertMessage: | ||
"${customMessage}Expected ${actual} (${actualType}) to be boolean", | ||
refuteMessage: "${customMessage}Expected ${actual} not to be boolean", | ||
"${customMessage}Expected ${value} (${actual}) to be boolean", | ||
refuteMessage: "${customMessage}Expected ${value} not to be boolean", | ||
expectation: "toBeBoolean", | ||
values: actualAndTypeOfMessageValues | ||
values: function(actual, message) { | ||
return { | ||
value: actual, | ||
actual: typeof actual, | ||
expected: "boolean", | ||
customMessage: message | ||
}; | ||
} | ||
}); | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
"use strict"; | ||
|
||
var actualAndTypeOfMessageValues = require("../actual-and-type-of-message-values"); | ||
|
||
module.exports = function(referee) { | ||
referee.add("isNumber", { | ||
assert: function(actual) { | ||
return typeof actual === "number" && !isNaN(actual); | ||
}, | ||
assertMessage: | ||
"${customMessage}Expected ${actual} (${actualType}) to be a non-NaN number", | ||
"${customMessage}Expected ${value} (${actual}) to be a non-NaN number", | ||
refuteMessage: | ||
"${customMessage}Expected ${actual} to be NaN or a non-number value", | ||
"${customMessage}Expected ${value} to be NaN or a non-number value", | ||
expectation: "toBeNumber", | ||
values: actualAndTypeOfMessageValues | ||
values: function(actual, message) { | ||
return { | ||
value: actual, | ||
actual: typeof actual, | ||
expected: "number", | ||
customMessage: message | ||
}; | ||
} | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
"use strict"; | ||
|
||
var actualAndTypeOfMessageValues = require("../actual-and-type-of-message-values"); | ||
|
||
module.exports = function(referee) { | ||
referee.add("isObject", { | ||
assert: function(actual) { | ||
return typeof actual === "object" && !!actual; | ||
}, | ||
assertMessage: | ||
"${customMessage}${actual} (${actualType}) expected to be object and not null", | ||
"${customMessage}${value} (${actual}) expected to be object and not null", | ||
refuteMessage: | ||
"${customMessage}${actual} expected to be null or not an object", | ||
"${customMessage}${value} expected to be null or not an object", | ||
expectation: "toBeObject", | ||
values: actualAndTypeOfMessageValues | ||
values: function(actual, message) { | ||
return { | ||
value: actual, | ||
actual: typeof actual, | ||
expected: "object", | ||
customMessage: message | ||
}; | ||
} | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
"use strict"; | ||
|
||
var actualAndTypeOfMessageValues = require("../actual-and-type-of-message-values"); | ||
|
||
module.exports = function(referee) { | ||
referee.add("isString", { | ||
assert: function(actual) { | ||
return typeof actual === "string"; | ||
}, | ||
assertMessage: | ||
"${customMessage}Expected ${actual} (${actualType}) to be string", | ||
refuteMessage: "${customMessage}Expected ${actual} not to be string", | ||
"${customMessage}Expected ${value} (${actual}) to be string", | ||
refuteMessage: "${customMessage}Expected ${value} not to be string", | ||
expectation: "toBeString", | ||
values: actualAndTypeOfMessageValues | ||
values: function(actual, message) { | ||
return { | ||
value: actual, | ||
actual: typeof actual, | ||
expected: "string", | ||
customMessage: message | ||
}; | ||
} | ||
}); | ||
}; |
This file contains 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
Oops, something went wrong.