92cd8e99ea64c313a8ba8ec68563ec15ecc94f4b.svn-base
2.27 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Test utils.betterErrors. utils.betterErrors should provide sensible error messages even when the error does not
* contain expected, actual or operator.
*/
var assert = require("../lib/assert");
var should = require("should");
var types = require("../lib/types");
var util = require('util');
var utils = require("../lib/utils");
function betterErrorStringFromError(error) {
var assertion = types.assertion({error: error});
var better = utils.betterErrors(assertion);
return better.error.stack.toString();
}
function performBasicChecks(betterErrorString) {
betterErrorString.should.include("AssertionError");
betterErrorString.should.include("test-bettererrors");
betterErrorString.should.not.include("undefined");
}
/**
* Control test. Provide an AssertionError that contains actual, expected operator values.
* @param test the test object from nodeunit
*/
exports.testEqual = function (test) {
try {
assert.equal(true, false);
} catch (error) {
var betterErrorString = betterErrorStringFromError(error);
performBasicChecks(betterErrorString);
betterErrorString.should.include("true");
betterErrorString.should.include("false");
betterErrorString.should.include("==");
test.done();
}
};
/**
* Test an AssertionError that does not contain actual, expected or operator values.
* @param test the test object from nodeunit
*/
exports.testAssertThrows = function (test) {
try {
assert.throws(function () {
});
} catch (error) {
var betterErrorString = betterErrorStringFromError(error);
performBasicChecks(betterErrorString);
test.done();
}
};
/**
* Test with an error that is not an AssertionError.
* @param test the test object from nodeunit
*/
exports.testNonAssertionError = function (test) {
try {
throw new Error("test error");
} catch (error) {
var betterErrorString = betterErrorStringFromError(error);
betterErrorString.should.not.include("AssertionError");
betterErrorString.should.include("Error");
betterErrorString.should.include("test error");
betterErrorString.should.include("test-bettererrors");
betterErrorString.should.not.include("undefined");
test.done();
}
};