Skip to content

Commit 3a5a5eb

Browse files
committed
adding test cases
1 parent 6324fff commit 3a5a5eb

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var lib = module.exports = {};
1515

1616
lib.nestedProperty = require('./nested_property');
1717
lib.isPlainObject = require('./is_plain_object');
18+
lib.isArray = require('./is_array');
1819

1920
var coerceModule = require('./coerce');
2021
lib.valObjects = coerceModule.valObjects;

src/lib/is_array.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
'use strict';
1010

1111
/**
12-
* Truncate a Float32Array to some length. A wrapper to support environments
13-
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
12+
* Return true for arrays, whether they're untyped or not.
1413
*/
1514
module.exports = function isArray(a) {
1615
return Array.isArray(a) || ArrayBuffer.isView(a);

test/jasmine/tests/is_array_test.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var Lib = require('@src/lib');
2+
3+
describe('isArray', function() {
4+
'use strict';
5+
6+
var isArray = Lib.isArray;
7+
8+
function A() {}
9+
10+
var shouldPass = [
11+
[],
12+
new Array(10),
13+
new Float32Array(1),
14+
new Int32Array([1, 2, 3])
15+
];
16+
17+
var shouldFail = [
18+
A,
19+
new A(),
20+
document,
21+
window,
22+
null,
23+
undefined,
24+
'string',
25+
true,
26+
false,
27+
NaN,
28+
Infinity,
29+
/foo/,
30+
'\n',
31+
new Date(),
32+
new RegExp('foo'),
33+
new String('string')
34+
];
35+
36+
shouldPass.forEach(function(obj) {
37+
it('treats ' + JSON.stringify(obj) + ' as an array', function() {
38+
expect(isArray(obj)).toBe(true);
39+
});
40+
});
41+
42+
shouldFail.forEach(function(obj) {
43+
it('treats ' + JSON.stringify(obj !== window ? obj : 'window') + ' as NOT an array', function() {
44+
expect(isArray(obj)).toBe(false);
45+
});
46+
});
47+
});

test/jasmine/tests/is_plain_object_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('isPlainObject', function() {
2020
null,
2121
undefined,
2222
[],
23+
new Float32Array(1),
2324
'string',
2425
true,
2526
false,

0 commit comments

Comments
 (0)