Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 99a7c50

Browse files
committed
more exact specs & $insert returns new array
1 parent 6355a46 commit 99a7c50

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.3.1
4+
5+
* $insert returns updated array
6+
37
## v0.3.0
48

59
* Lots of new methods

better-array.js

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
},
9090
$insert: function $insert(index, element){
9191
this.native.splice(index, 0, element);
92+
return this.native;
9293
},
9394
isEmpty: function isEmpty(){
9495
return this.native.length === 0;

spec/better_array_spec.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('BetterArray', function() {
2020
expect( ba([2, 3, 4]).at(1) ).toEqual(3);
2121
});
2222

23-
it("returns values at that indexes for multiple argument", function() {
23+
it("returns values at that indexes for multiple arguments", function() {
2424
expect( ba([2, 3, 4]).at(0, 2) ).toEqual([2, 4]);
2525
});
2626
});
@@ -31,6 +31,11 @@ describe('BetterArray', function() {
3131
ba(array).$clear();
3232
expect( array ).toEqual([]);
3333
});
34+
35+
it("returns the empty array", function(){
36+
var array = [2, 3, 4];
37+
expect( ba(array).$clear() ).toEqual([]);
38+
});
3439
});
3540

3641
describe('.clone', function() {
@@ -52,7 +57,7 @@ describe('BetterArray', function() {
5257
});
5358

5459
describe('.contains', function() {
55-
it("returns array with no double entries", function() {
60+
it("checks if an element is included in the array", function() {
5661
expect( ba([2, 3, 4]).contains(4) ).toEqual(true);
5762
expect( ba([2, 3, 4]).contains(5) ).toEqual(false);
5863
});
@@ -155,6 +160,11 @@ describe('BetterArray', function() {
155160
ba(array).$insert(1, 2.5);
156161
expect( array ).toEqual([2, 2.5, 3, 4]);
157162
});
163+
164+
it("returns the updated array", function() {
165+
var array = [2, 3, 4];
166+
expect( ba(array).$insert(1, 2.5) ).toEqual([2, 2.5, 3, 4]);
167+
});
158168
});
159169

160170
describe('.isEmpty', function() {
@@ -193,13 +203,13 @@ describe('BetterArray', function() {
193203

194204
describe('.minus', function() {
195205
it("takes values from array without the ones from the other array", function() {
196-
expect( ba([2, 3, 4]).minus([3, 4, 5]) ).toEqual([2]);
206+
expect( ba([2, 3, 4] ).minus([3, 4, 5]) ).toEqual([2]);
197207
});
198208
});
199209

200210
describe('.or', function() {
201211
it("returns a uniqe array out of all elements of both arrays", function() {
202-
expect( ba([2, 3, 4]).or([3, 4, 4, 5]) ).toEqual([2, 3, 4, 5]);
212+
expect( ba([2, 3, 4] ).or([3, 4, 4, 5]) ).toEqual([2, 3, 4, 5]);
203213
});
204214
});
205215

@@ -285,17 +295,19 @@ describe('BetterArray', function() {
285295
});
286296

287297
it("rotates by 1 without argument", function() {
288-
expect( ba([2, 3, 4, 5, 6]).rotate(1) ).toEqual([3, 4, 5, 6, 2]);
298+
expect( ba([2, 3, 4, 5, 6]).rotate() ).toEqual([3, 4, 5, 6, 2]);
289299
});
290300
});
291301

292302
describe('.$set', function() {
293303
it("sets the element at this index and returns array", function() {
294-
expect( ba([2, 3, 4]).$set(1, "three") ).toEqual([2, "three", 4]);
304+
var array = [2, 3, 4];
305+
ba(array).$set(1, "three")
306+
expect( array ).toEqual([2, "three", 4]);
295307
});
296308

297-
it("returns values at that indexes for multiple argument", function() {
298-
expect( ba([2, 3, 4]).at(0, 2) ).toEqual([2, 4]);
309+
it("returns updated array", function() {
310+
expect( ba([2, 3, 4]).$set(1, "three") ).toEqual([2, "three", 4]);
299311
});
300312
});
301313

0 commit comments

Comments
 (0)