Skip to content

Commit

Permalink
Adding some tests to other Array.prototype methods to check object-bo…
Browse files Browse the repository at this point in the history
…xing of context argument.
  • Loading branch information
ljharb committed Jan 4, 2014
1 parent fa593e3 commit 55e7890
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions tests/spec/s-array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var toString = Object.prototype.toString;

describe('Array', function() {
var testSubject;
beforeEach(function() {
Expand Down Expand Up @@ -76,8 +78,7 @@ describe('Array', function() {
});

describe('strings', function() {
var str = 'Hello, World!',
toString = Object.prototype.toString;
var str = 'Hello, World!';
it('should iterate all in a string', function() {
actual = [];
Array.prototype.forEach.call(str, function(item, index) {
Expand All @@ -93,13 +94,14 @@ describe('Array', function() {
}, o);
expect(actual).toExactlyMatch(str.split(''));
});
it('should have String object for third argument of callback', function() {
Array.prototype.forEach.call(str, function(item, index, obj) {
actual = obj;
});
expect(typeof actual).toBe("object");
expect(toString.call(actual)).toBe("[object String]");
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.forEach.call('foo', function(item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});
describe('some', function() {
Expand Down Expand Up @@ -196,6 +198,14 @@ describe('Array', function() {
}, o);
expect(actual).toExactlyMatch(expected);
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.some.call('foo', function(item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});
describe('every', function() {
var actual, expected, numberOfRuns;
Expand Down Expand Up @@ -294,6 +304,14 @@ describe('Array', function() {
}, o);
expect(actual).toExactlyMatch(expected);
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.every.call('foo', function(item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});

describe('indexOf', function() {
Expand Down Expand Up @@ -651,6 +669,14 @@ describe('Array', function() {
expect(testSubject).toExactlyMatch(copy);
});
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.filter.call('foo', function(item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});
describe('map', function() {
var callback;
Expand Down Expand Up @@ -767,6 +793,14 @@ describe('Array', function() {
expect(i).toBe(3);
});
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.map.call('foo', function(item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});

describe('reduce', function() {
Expand Down Expand Up @@ -916,6 +950,14 @@ describe('Array', function() {
expect(testSubject.reduce.length).toBe(1);
});
});
it('should have a boxed object as list argument of callback', function() {
var actual;
Array.prototype.reduce.call('foo', function(accumulator, item, index, list) {
actual = list;
});
expect(typeof actual).toBe('object');
expect(toString.call(actual)).toBe('[object String]');
});
});
describe('reduceRight', function() {
beforeEach(function() {
Expand Down

0 comments on commit 55e7890

Please sign in to comment.