willError
Requests that [can-log/dev/dev.error canDev.error] track and notify about matching errors.
dev.willError(expected, [fn])
Parameters
- expected
{String|Regexp}
:The error message to check for
- fn
{function(String, Boolean)}
:an optional callback to fire on every error; each call has the actual error message and a Boolean indicating whether it was matched
Returns
{function}
:
A function that tears down the error check and returns the number of matched errors when called.
willError()
takes either a String or a RegExp as its expected
error, and does a full, case-sensitive String
match in the case of a String, or a regex test in the case of a RegExp, for every error logged through
[can-log/dev/dev.error]. In addition, if fn
is provided, it is fired on every error logged by dev.error
with the content of the error message and whether it matched expected
.
willError()
returns a teardown function, which must be called at least once to disable the tracking of the matched
error. when called, the teardown function returns the number of times expected
was matched by a dev error.
var dev = require('can-log/dev/dev');
var devHelpers = require('can-test-helpers/lib/dev');
var finishErrorCheck = devHelpers.willError("something evil", function(message, match) {
message; // -> "something evil"
match; // true
});
canDev.error("something evil");
finishErrorCheck(); // -> 1