Name: js-handler/node_modules/nodeunit/test/test-bettererrors.js 
1:
/*
2:
 *   Test utils.betterErrors. utils.betterErrors should provide sensible error messages even when the error does not
3:
 *   contain expected, actual or operator.
4:
 */
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");
10:
 
11:
function betterErrorStringFromError(error) {
12:
    var assertion = types.assertion({error: error});
13:
    var better = utils.betterErrors(assertion);
14:
    return better.error.stack.toString();
15:
}
16:
 
17:
function performBasicChecks(betterErrorString) {
18:
    betterErrorString.should.include("AssertionError");
19:
    betterErrorString.should.include("test-bettererrors");
20:
    betterErrorString.should.not.include("undefined");
21:
}
22:
 
23:
/**
24:
 * Control test. Provide an AssertionError that contains actual, expected operator values.
25:
 * @param test the test object from nodeunit
26:
 */
27:
exports.testEqual = function (test) {
28:
    try {
29:
        assert.equal(true, false);
30:
    } catch (error) {
31:
        var betterErrorString = betterErrorStringFromError(error);
32:
        performBasicChecks(betterErrorString);
33:
        betterErrorString.should.include("true");
34:
        betterErrorString.should.include("false");
35:
        betterErrorString.should.include("==");
36:
        test.done();
37:
    }
38:
};
39:
 
40:
/**
41:
 * Test an AssertionError that does not contain actual, expected or operator values.
42:
 * @param test the test object from nodeunit
43:
 */
44:
exports.testAssertThrows = function (test) {
45:
    try {
46:
        assert.throws(function () {
47:
        });
48:
    } catch (error) {
49:
        var betterErrorString = betterErrorStringFromError(error);
50:
        performBasicChecks(betterErrorString);
51:
        test.done();
52:
    }
53:
};
54:
 
55:
/**
56:
 * Test with an error that is not an AssertionError.
57:
 *
58:
 * This function name MUST NOT include "AssertionError" because one of the
59:
 * tests it performs asserts that the returned error string does not contain
60:
 * the "AssertionError" term. If this function name does include that term, it
61:
 * will show up in the stack trace and the test will fail!
62:
 * @param test the test object from nodeunit
63:
 */
64:
exports.testErrorIsNotAssertion = function (test) {
65:
    try {
66:
        throw new Error("test error");
67:
    } catch (error) {
68:
        var betterErrorString = betterErrorStringFromError(error);
69:
        betterErrorString.should.not.include("AssertionError");
70:
        betterErrorString.should.include("Error");
71:
        betterErrorString.should.include("test error");
72:
        betterErrorString.should.include("test-bettererrors");
73:
        betterErrorString.should.not.include("undefined");
74:
        test.done();
75:
    }
76:
};