Skip to content

Commit

Permalink
Updated tests for all array accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
ascartabelli committed May 27, 2016
1 parent c25994b commit fa62c11
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dist/lamb.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @overview lamb - A lightweight, and docile, JavaScript library to help embracing functional programming.
* @author Andrea Scartabelli <andrea.scartabelli@gmail.com>
* @version 0.28.0-alpha.5
* @version 0.28.0-alpha.6
* @module lamb
* @license MIT
* @preserve
Expand All @@ -18,7 +18,7 @@
* @category Core
* @type String
*/
lamb._version = "0.28.0-alpha.5";
lamb._version = "0.28.0-alpha.6";

// alias used as a placeholder argument for partial application
var _ = lamb;
Expand Down
4 changes: 2 additions & 2 deletions dist/lamb.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lamb.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"coveralls": "gulp coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"tonicExample": "var _ = require('lamb');",
"version": "0.28.0-alpha.5",
"version": "0.28.0-alpha.6",
"devDependencies": {
"coveralls": "^2.11.9",
"gulp": "^3.9.1",
Expand Down
20 changes: 12 additions & 8 deletions test/spec/accessorsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("lamb.accessors", function () {
expect(lamb.getAt(-2)(s)).toBe("c");
});

it("should throw an error in no array-like object is supplied", function () {
it("should throw an exception if supplied with `null` or `undefined´ instead of an array-like", function () {
expect(function () { lamb.getIndex(null, 2); }).toThrow();
expect(function () { lamb.getIndex(void 0, 2); }).toThrow();
expect(function () { lamb.getAt(2)(null); }).toThrow();
Expand All @@ -35,7 +35,7 @@ describe("lamb.accessors", function () {
expect(function () { lamb.last(void 0); }).toThrow();
});

it("should return undefined when the object isn't an array-like, no index is supplied, the index isn't an integer or the index is out of bounds", function () {
it("should return undefined for every other value and when no index is supplied, the index isn't an integer or the index is out of bounds", function () {
[-6, 66, NaN, null, void 0, {}, [], [2], "a", "1", "1.5", 1.5].forEach(function (v) {
expect(lamb.getAt(v)(arr)).toBeUndefined();
});
Expand Down Expand Up @@ -121,12 +121,14 @@ describe("lamb.accessors", function () {
expect(newS).toEqual(["h", "e", "l", "l", "o"]);
});

it("should throw an exception if no array-object is supplied", function () {
expect(lamb.setAt(0, 99)).toThrow();
it("should throw an exception if supplied with `null` or `undefined´ instead of an array-like", function () {
expect(function () { lamb.setAt(0, 99)(null); }).toThrow();
expect(function () { lamb.setAt(0, 99)(void 0); }).toThrow();
expect(function () { lamb.setIndex(null, 0, 99); }).toThrow();
expect(function () { lamb.setIndex(void 0, 0, 99); }).toThrow();
});

it("should return an empty array if a non-array-like object is supplied", function () {
it("should return an empty array for every other value", function () {
[/foo/, 1, function () {}, NaN, true, new Date()].forEach(function (v) {
expect(lamb.setIndex(v, 2, 99)).toEqual([]);
expect(lamb.setAt(2, 99)(v)).toEqual([]);
Expand Down Expand Up @@ -214,12 +216,14 @@ describe("lamb.accessors", function () {
expect(lamb.updateAt(10, toUpperCase)(s)).toEqual(["h", "e", "l", "l", "o"]);
});

it("should throw an exception if no array-object is supplied", function () {
it("should throw an exception if supplied with `null` or `undefined´ instead of an array-like", function () {
expect(function () { lamb.updateIndex(null, 0, fn99); }).toThrow();
expect(lamb.updateAt(0, fn99)).toThrow();
expect(function () { lamb.updateIndex(void 0, 0, fn99); }).toThrow();
expect(function () { lamb.updateAt(0, fn99)(null); }).toThrow();
expect(function () { lamb.updateAt(0, fn99)(void 0); }).toThrow();
});

it("should return an empty array if a non-array-like object is supplied", function () {
it("should return an empty array for every other value", function () {
[/foo/, 1, function () {}, NaN, true, new Date()].forEach(function (v) {
expect(lamb.updateIndex(v, 2, fn99)).toEqual([]);
expect(lamb.updateAt(2, fn99)(v)).toEqual([]);
Expand Down

0 comments on commit fa62c11

Please sign in to comment.