| 1.0 Single Argument Testing |
| The following tests forEach with one argument, the callback. It should print the contents of the array [2, 5, 9] alongside each index. |
| |
| [0] is 2 |
| [1] is 5 |
| [2] is 9 |
| |
| 2.0 Two Argument Testing |
| The following tests forEach with two arguments, the callback and the applied "this" object. It should print the contents of the array. |
| |
| 2 |
| 5 |
| 9 |
| |
| 3.0 Array Mutation Tests |
| These tests the affects of array mutation during execution of forEach. |
| |
| 3.1 Array Element Removal |
| This test removes elements from the array, these elements should thus not appear since forEach doesn't iterate over non-existing properties. |
| |
| [0] is 2 |
| [1] is 5 |
| |
| 3.2 Array Element Addition |
| This test adds elements to the array, these elements should not appear since forEach uses the original length to create the range it iterates over. It should be identical to 1.0. |
| |
| [0] is 2 |
| [1] is 5 |
| [2] is 9 |
| |
| 3.3 Array Element Changing |
| This test changes elements in the array, these elements should appear in their mutated form when reached by forEach. |
| |
| [0] is 2 |
| [1] is 5 |
| [2] is changed |
| |
| 4.0 Exception Test |
| This test uses a function that throws an exception, and thus halts the execution of forEach. |
| |
| [0] is 2 |
| [1] is 5 |
| Exception thrown, execution halted! |
| |
| 5.0 Wrong Type for Callback Test This test sends in incorrect types for the callback parameter of forEach. An exception should be thrown in each case. There should be 6 type errors (and no crashes!): |
| |
| TypeError: Array.prototype.forEach callback must be a function |
| TypeError: Array.prototype.forEach callback must be a function |
| TypeError: Array.prototype.forEach callback must be a function |
| TypeError: Array.prototype.forEach callback must be a function |
| TypeError: Array.prototype.forEach callback must be a function |
| TypeError: Array.prototype.forEach callback must be a function |
| |
| 6.0 Behavior for Holes in Arrays |
| This test checks that holes in arrays (indexes which have been deleted or are not present) are not included in enumeration: |
| |
| Manually deleted index not enumerated |
| Array created using constructor has no properties, so no indexes enumerated |
| |
| 7.0 Return Value |
| This test checks that the return value of Array.prototype.forEach is undefined: |
| |
| Return value is undefined! |
| |