-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |