2 * Test utils.betterErrors. utils.betterErrors should provide sensible error messages even when the error does not
3 * contain expected, actual or operator.
5 var assert = require("../lib/assert");
6 var should = require("should");
7 var types = require("../lib/types");
8 var util = require('util');
9 var utils = require("../lib/utils");
11 function betterErrorStringFromError(error) {
12 var assertion = types.assertion({error: error});
13 var better = utils.betterErrors(assertion);
14 return better.error.stack.toString();
17 function performBasicChecks(betterErrorString) {
18 betterErrorString.should.include("AssertionError");
19 betterErrorString.should.include("test-bettererrors");
20 betterErrorString.should.not.include("undefined");
24 * Control test. Provide an AssertionError that contains actual, expected operator values.
25 * @param test the test object from nodeunit
27 exports.testEqual = function (test) {
29 assert.equal(true, false);
31 var betterErrorString = betterErrorStringFromError(error);
32 performBasicChecks(betterErrorString);
33 betterErrorString.should.include("true");
34 betterErrorString.should.include("false");
35 betterErrorString.should.include("==");
41 * Test an AssertionError that does not contain actual, expected or operator values.
42 * @param test the test object from nodeunit
44 exports.testAssertThrows = function (test) {
46 assert.throws(function () {
49 var betterErrorString = betterErrorStringFromError(error);
50 performBasicChecks(betterErrorString);
56 * Test with an error that is not an AssertionError.
57 * @param test the test object from nodeunit
59 exports.testNonAssertionError = function (test) {
61 throw new Error("test error");
63 var betterErrorString = betterErrorStringFromError(error);
64 betterErrorString.should.not.include("AssertionError");
65 betterErrorString.should.include("Error");
66 betterErrorString.should.include("test error");
67 betterErrorString.should.include("test-bettererrors");
68 betterErrorString.should.not.include("undefined");