Skip to content

Commit

Permalink
Foreach: add a missing test file.
Browse files Browse the repository at this point in the history
I forgot a file in 5fcfa93, here it is.
  • Loading branch information
dduponchel committed Feb 2, 2016
1 parent f7f3fe5 commit 1c127bc
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/asserts/foreach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* jshint qunit: true */
/* global JSZip,JSZipTestUtils */
'use strict';

QUnit.module("forEach");

test("forEach works on /", function (assert) {
var zip = JSZipTestUtils.createZipAll();
var count = 0;
var calls = [];

assert.equal(zip.root, "");

zip.forEach(function (path, elt) {
assert.equal(path, elt.name, "the full path is given on / for " + elt.name);
count++;
calls.push(path);
});

equal(count, 3, "the callback has been called the right number of times");
assert.deepEqual(calls, ["Hello.txt", "images/", "images/smile.gif"], "all paths have been called");
});

test("forEach works on a sub folder", function (assert) {
var zip = new JSZip();
var sub = zip.folder("subfolder");
sub.file("Hello.txt", "Hello World\n");
sub.folder("images").file("smile.gif", "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs=", {base64: true});
var count = 0;
var calls = [];

assert.ok(zip.file("subfolder/Hello.txt"));
assert.equal(sub.root, "subfolder/");

sub.forEach(function (path, elt) {
assert.equal(path, elt.name.substr("subfolder/".length), "the full path is given on subfolder/ for " + path);
count++;
calls.push(path);
});

equal(count, 3, "the callback has been called the right number of times");
assert.deepEqual(calls, ["Hello.txt", "images/", "images/smile.gif"], "all paths have been called");
});

0 comments on commit 1c127bc

Please sign in to comment.