Created
April 17, 2014 16:00
-
-
Save subtubes-io/10994281 to your computer and use it in GitHub Desktop.
Most fo this suite of tests covers mutator functions for arrays
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
(function () { | |
describe("Array", function () { | |
//part 2 | |
it("Array push()", function () { | |
var arr = []; | |
arr.push(2); | |
expect(arr.length).toBe(1); | |
}); | |
it("Array pop()", function () { | |
var arr = [0, 1, 2]; | |
arr.pop(); | |
expect(arr).toEqual([0, 1]); | |
}); | |
it("Array unshift()", function () { | |
var arr = [1, 2]; | |
arr.unshift(0); | |
expect(arr).toEqual([0, 1, 2]); | |
}); | |
it("Array shift", function () { | |
var arr = [1, 2]; | |
arr.shift(); | |
expect(arr).toEqual([2]); | |
}); | |
it("Array splice()", function () { | |
var arr = [1, 2, 3, 4, 5]; | |
var spliced = arr.splice(0, 3); | |
expect(spliced).toEqual([1, 2, 3]); | |
expect(arr).toEqual([4,5]); | |
}); | |
it("Array concat()", function () { | |
var arr = [1,2,3,4,5]; | |
var arr2 = [6,7,8,9,0]; | |
var concatenated = arr2.concat(arr); | |
expect(concatenated).toEqual([6,7,8,9,0,1,2,3,4,5]) | |
}); | |
it("Array join()", function () { | |
var arr = [1,2,3,4]; | |
var joined = arr.join(""); | |
expect(joined).toEqual('1234'); | |
}); | |
it("Array indexOf()", function () { | |
var arr = [1,4,3,2]; | |
var idx = arr.indexOf(4); | |
expect(idx).toBe(1); | |
}) | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment