Name: js-handler/node_modules/nodeunit/test/test-failing-callbacks.js 
1:
var nodeunit = require('../lib/nodeunit');
2:
 
3:
 
4:
exports.testFailingLog = function (test) {
5:
    test.expect(3);
6:
 
7:
    // this is meant to bubble to the top, and will be ignored for the purposes
8:
    // of testing:
9:
    var ignored_error = new Error('ignore this callback error');
10:
    var err_handler = function (err) {
11:
        if (err && err.message !== ignored_error.message) {
12:
            throw err;
13:
        }
14:
    };
15:
    process.addListener('uncaughtException', err_handler);
16:
 
17:
    // A failing callback should not affect the test outcome
18:
    var testfn = function (test) {
19:
        test.ok(true, 'test.ok');
20:
        test.done();
21:
    };
22:
    nodeunit.runTest('testname', testfn, {
23:
        log: function (assertion) {
24:
            test.ok(true, 'log called');
25:
            throw ignored_error;
26:
        },
27:
        testDone: function (name, assertions) {
28:
            test.equals(assertions.failures(), 0, 'failures');
29:
            test.equals(assertions.length, 1, 'total');
30:
            process.removeListener('uncaughtException', err_handler);
31:
        }
32:
    }, test.done);
33:
};
34:
 
35:
exports.testFailingTestDone = function (test) {
36:
    test.expect(2);
37:
 
38:
    var ignored_error = new Error('ignore this callback error');
39:
    var err_handler = function (err) {
40:
        if (err && err.message !== ignored_error.message) {
41:
            throw err;
42:
        }
43:
    };
44:
    process.addListener('uncaughtException', err_handler);
45:
 
46:
    // A failing callback should not affect the test outcome
47:
    var testfn = function (test) {
48:
        test.done();
49:
    };
50:
    nodeunit.runTest('testname', testfn, {
51:
        log: function (assertion) {
52:
            test.ok(false, 'log should not be called');
53:
        },
54:
        testDone: function (name, assertions) {
55:
            test.equals(assertions.failures(), 0, 'failures');
56:
            test.equals(assertions.length, 0, 'total');
57:
            process.nextTick(function () {
58:
                process.removeListener('uncaughtException', err_handler);
59:
                test.done();
60:
            });
61:
            throw ignored_error;
62:
        }
63:
    }, function () {});
64:
};
65:
 
66:
exports.testAssertionObj = function (test) {
67:
    test.expect(4);
68:
    var testfn = function (test) {
69:
        test.ok(true, 'ok true');
70:
        test.done();
71:
    };
72:
    nodeunit.runTest('testname', testfn, {
73:
        log: function (assertion) {
74:
            test.ok(assertion.passed() === true, 'assertion.passed');
75:
            test.ok(assertion.failed() === false, 'assertion.failed');
76:
        },
77:
        testDone: function (name, assertions) {
78:
            test.equals(assertions.failures(), 0, 'failures');
79:
            test.equals(assertions.length, 1, 'total');
80:
        }
81:
    }, test.done);
82:
};
83:
 
84:
exports.testLogOptional = function (test) {
85:
    test.expect(2);
86:
    var testfn = function (test) {
87:
        test.ok(true, 'ok true');
88:
        test.done();
89:
    };
90:
    nodeunit.runTest('testname', testfn, {
91:
        testDone: function (name, assertions) {
92:
            test.equals(assertions.failures(), 0, 'failures');
93:
            test.equals(assertions.length, 1, 'total');
94:
        }
95:
    }, test.done);
96:
};
97:
 
98:
exports.testExpectWithFailure = function (test) {
99:
    test.expect(3);
100:
    var testfn = function (test) {
101:
        test.expect(1);
102:
        test.ok(false, 'test.ok');
103:
        test.done();
104:
    };
105:
    nodeunit.runTest('testname', testfn, {
106:
        log: function (assertion) {
107:
            test.equals(assertion.method, 'ok', 'assertion.method');
108:
        },
109:
        testDone: function (name, assertions) {
110:
            test.equals(assertions.failures(), 1, 'failures');
111:
            test.equals(assertions.length, 1, 'total');
112:
        }
113:
    }, test.done);
114:
};