| OLD | NEW |
| 1 /* global self */ | 1 /* global self */ |
| 2 | 2 |
| 3 // testharness.js has the higher priority. | 3 // testharness.js has the higher priority. |
| 4 var TESTHARNESS = true; | 4 var TESTHARNESS = true; |
| 5 var JSTEST = false; | 5 var JSTEST = false; |
| 6 | 6 |
| 7 (function () { | 7 (function () { |
| 8 // Selected properies from testharness.js | 8 // Selected properies from testharness.js |
| 9 var testharnessProperties = [ | 9 var testharnessProperties = [ |
| 10 'test', 'async_test', 'promise_test', 'promise_rejects', | 10 'test', 'async_test', 'promise_test', 'promise_rejects', |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 throw failureMessage; | 597 throw failureMessage; |
| 598 }; | 598 }; |
| 599 | 599 |
| 600 // Check if |target| is equal to |value|. | 600 // Check if |target| is equal to |value|. |
| 601 // | 601 // |
| 602 // Example: | 602 // Example: |
| 603 // Should('Zero', 0).beEqualTo(0); | 603 // Should('Zero', 0).beEqualTo(0); |
| 604 // Result: | 604 // Result: |
| 605 // "PASS Zero is equal to 0." | 605 // "PASS Zero is equal to 0." |
| 606 ShouldModel.prototype.beEqualTo = function (value) { | 606 ShouldModel.prototype.beEqualTo = function (value) { |
| 607 var type = typeof value; | 607 if (value != null) { |
| 608 this._assert(type === 'number' || type === 'string', | 608 var type = typeof value; |
| 609 'value should be number or string for', value); | 609 this._assert(type === 'number' || type === 'string' || type === 'boo
lean', |
| 610 'value should be number, string, or boolean for', value
); |
| 611 } |
| 610 | 612 |
| 611 this._checkNaN(value, 'EXPECTED'); | 613 this._checkNaN(value, 'EXPECTED'); |
| 612 | 614 |
| 613 var outputValue = value; | 615 var outputValue = value; |
| 614 if (type === 'string') | 616 if (type === 'string') |
| 615 outputValue = '"' + outputValue + '"'; | 617 outputValue = '"' + outputValue + '"'; |
| 616 if (this.target === value) { | 618 if (this.target === value) { |
| 617 var outputValue = (type === 'string') ? '"' + value + '"' : value; | 619 var outputValue = (type === 'string') ? '"' + value + '"' : value; |
| 618 this._testPassed('is equal to ' + outputValue); | 620 this._testPassed('is equal to ' + outputValue); |
| 619 } else { | 621 } else { |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 // "PASS My promise rejected correctly (with _ERROR_)." | 1133 // "PASS My promise rejected correctly (with _ERROR_)." |
| 1132 // "FAIL My promise resolved incorrectly." | 1134 // "FAIL My promise resolved incorrectly." |
| 1133 ShouldModel.prototype.beRejected = function () { | 1135 ShouldModel.prototype.beRejected = function () { |
| 1134 return this.target.then(function () { | 1136 return this.target.then(function () { |
| 1135 this._testFailed('resolved incorrectly'); | 1137 this._testFailed('resolved incorrectly'); |
| 1136 }.bind(this), function (err) { | 1138 }.bind(this), function (err) { |
| 1137 this._testPassed('rejected correctly (with ' + err + ')'); | 1139 this._testPassed('rejected correctly (with ' + err + ')'); |
| 1138 }.bind(this)); | 1140 }.bind(this)); |
| 1139 }; | 1141 }; |
| 1140 | 1142 |
| 1143 // A summary message |
| 1144 // |
| 1145 // Example: |
| 1146 // Should("Summary1", true).summarize("passed1", "failed1"); |
| 1147 // Should("Summary2", false).summarize("passed2", "failed2"); |
| 1148 // Result: |
| 1149 // "PASS Summary1: passed1." |
| 1150 // "FAIL Summary2: failed2." |
| 1151 ShouldModel.prototype.summarize = function (pass, fail) { |
| 1152 if (this.target) |
| 1153 this._testPassed(pass); |
| 1154 else |
| 1155 this._testFailed(fail); |
| 1156 return this._success; |
| 1157 } |
| 1158 |
| 1141 // Should() method. | 1159 // Should() method. |
| 1142 // | 1160 // |
| 1143 // |desc| is the description of the task or check and |target| is a value | 1161 // |desc| is the description of the task or check and |target| is a value |
| 1144 // needs to be checked or a task to be performed. |opt| contains options for | 1162 // needs to be checked or a task to be performed. |opt| contains options for |
| 1145 // printing out log messages: options are |opt.numberOfErrorLog| and | 1163 // printing out log messages: options are |opt.numberOfErrorLog| and |
| 1146 // |opts.numberOfArrayLog|. | 1164 // |opts.numberOfArrayLog|. |
| 1147 return function (desc, target, opts) { | 1165 return function (desc, target, opts) { |
| 1148 var _opts = { | 1166 var _opts = { |
| 1149 numberOfErrorLog: 8, | 1167 numberOfErrorLog: 8, |
| 1150 numberOfArrayLog: 16, | 1168 numberOfArrayLog: 16, |
| 1151 verbose: true | 1169 verbose: true |
| 1152 }; | 1170 }; |
| 1153 | 1171 |
| 1154 if (opts instanceof Object) { | 1172 if (opts instanceof Object) { |
| 1155 if (opts.hasOwnProperty('numberOfErrorLog')) | 1173 if (opts.hasOwnProperty('numberOfErrorLog')) |
| 1156 _opts.numberOfErrorLog = opts.numberOfErrorLog; | 1174 _opts.numberOfErrorLog = opts.numberOfErrorLog; |
| 1157 if (opts.hasOwnProperty('numberOfArrayLog')) | 1175 if (opts.hasOwnProperty('numberOfArrayLog')) |
| 1158 _opts.numberOfArrayLog = opts.numberOfArrayLog; | 1176 _opts.numberOfArrayLog = opts.numberOfArrayLog; |
| 1159 if (opts.hasOwnProperty('brief')) | 1177 if (opts.hasOwnProperty('brief')) |
| 1160 _opts.brief = opts.brief; | 1178 _opts.brief = opts.brief; |
| 1161 if (opts.hasOwnProperty('precision')) | 1179 if (opts.hasOwnProperty('precision')) |
| 1162 _opts.precision = opts.precision; | 1180 _opts.precision = opts.precision; |
| 1163 } | 1181 } |
| 1164 | 1182 |
| 1165 return new ShouldModel(desc, target, _opts); | 1183 return new ShouldModel(desc, target, _opts); |
| 1166 }; | 1184 }; |
| 1167 | 1185 |
| 1168 })(); | 1186 })(); |
| OLD | NEW |