Skip to content

Commit

Permalink
Add first tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alrik committed Feb 15, 2018
1 parent 037e75c commit d07e806
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/iterate-array.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { assert } = require('chai');
const iterate = require('../index');

describe('iterate arrays', function () {
it('should iterate all items in an array', function() {
const steps = [];
const testArr = ['a', 'b', 'c', 'd', 'e'];

iterate(testArr, (item, index, arr) => steps.push([item, index, arr]));

assert.deepEqual(steps, [
['a', 0, testArr],
['b', 1, testArr],
['c', 2, testArr],
['d', 3, testArr],
['e', 4, testArr],
]);
});
});
34 changes: 34 additions & 0 deletions test/iterate-strings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { assert } = require('chai');
const iterate = require('../index');

describe('iterate string', function () {
it('should iterate all chars in a primative string', function() {
const steps = [];
const testStr = 'abcde';

iterate(testStr, (char, index, str) => steps.push([char, index, str]));

assert.deepEqual(steps, [
['a', 0, testStr],
['b', 1, testStr],
['c', 2, testStr],
['d', 3, testStr],
['e', 4, testStr],
]);
});

it('should iterate all chars in a string instance', function() {
const steps = [];
const testStr = new String('abcde');

iterate(testStr, (char, index, str) => steps.push([char, index, str]));

assert.deepEqual(steps, [
['a', 0, testStr],
['b', 1, testStr],
['c', 2, testStr],
['d', 3, testStr],
['e', 4, testStr],
]);
});
});
19 changes: 19 additions & 0 deletions test/iterate-typed-array.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { assert } = require('chai');
const iterate = require('../index');

describe('iterate typed arrays', function () {
it('should iterate all items in a typed array', function() {
const steps = [];
const testArr = new Int32Array([1, 2, 3, 4, 5]);

iterate(testArr, (number, index, arr) => steps.push([number, index, arr]));

assert.deepEqual(steps, [
[1, 0, testArr],
[2, 1, testArr],
[3, 2, testArr],
[4, 3, testArr],
[5, 4, testArr],
]);
});
});

0 comments on commit d07e806

Please sign in to comment.