Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / 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  * @param test the test object from nodeunit
58  */
59 exports.testNonAssertionError = function (test) {
60     try {
61         throw new Error("test error");
62     } catch (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");
69         test.done();
70     }
71 };