Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #14 Added unit tests for when/apply

  • Loading branch information...
commit 91d03560d248489432cf4bcebb44a770dad29029 1 parent 33388b1
@briancavalier authored
Showing with 59 additions and 7 deletions.
  1. +2 −0  test/all.js
  2. +50 −0 test/apply.html
  3. +7 −7 test/checkHandlers.html
View
2  test/all.js
@@ -17,4 +17,6 @@ doh.registerUrl('when.reduce', '../../reduce.html');
doh.registerUrl('checkHandlers', '../../checkHandlers.html');
+doh.registerUrl('when/apply', '../../apply.html');
+
doh.run();
View
50 test/apply.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html lang="en-US">
+<head>
+ <meta charset="UTF-8">
+ <title>check handler parameters Unit Tests</title>
+ <script src="util/doh/runner.js"></script>
+ <script src="test-config.js"></script>
+ <script src="../apply.js"></script>
+ <script>
+
+ (function(global, doh, async) {
+
+ // variadic arguments-based callback
+ function f() {
+ var sum, i = arguments.length;
+
+ sum = 0;
+ while(i) {
+ sum += arguments[--i];
+ }
+
+ return sum;
+ }
+
+ doh.register('checkHandlers', [
+ function testApplySpreadsArray() {
+ doh.assertEqual(15, when_apply(f)([1,2,3,4,5]));
+ },
+ function testApplyFailsForNonArrayLike() {
+ var success = false;
+
+ try {
+ when_apply(f)(1,2,3,4,5);
+ } catch(e) {
+ success = true;
+ }
+
+ doh.assertTrue(success);
+ }
+ ]);
+
+ doh.run();
+
+ })(window, doh, doh.asyncHelper);
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 test/checkHandlers.html
@@ -13,13 +13,14 @@
function assertThenThrows() {
var success, d;
- success = true;
+ success = false;
d = when.defer();
try {
d.promise.then.apply(d.promise, arguments);
- success = false;
- } catch(e) {}
+ } catch(e) {
+ success = true;
+ }
doh.assertTrue(success);
}
@@ -27,14 +28,13 @@
function assertThenAllows() {
var success, d;
- success = true;
+ success = false;
d = when.defer();
try {
d.promise.then.apply(d.promise, arguments);
- } catch(e) {
- success = false;
- }
+ success = true;
+ } catch(e) {}
doh.assertTrue(success);
}
Please sign in to comment.
Something went wrong with that request. Please try again.