Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 1, 2019
1 parent 28f2042 commit 2ab2cc4
Show file tree
Hide file tree
Showing 41 changed files with 306 additions and 60 deletions.
4 changes: 4 additions & 0 deletions tests/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const STRICT = !function () {
return this;
}();

export const STRICT_THIS = (function () {
return this;
})();

export const FREEZING = !function () {
try {
return Object.isExtensible(Object.preventExtensions({}));
Expand Down
17 changes: 14 additions & 3 deletions tests/pure/esnext.async-iterator.drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AsyncIterator from 'core-js-pure/features/async-iterator';
import { createIterator } from '../helpers/helpers';

QUnit.test('AsyncIterator#drop', assert => {
assert.expect(8);
assert.expect(12);
const async = assert.async();
const { drop } = AsyncIterator.prototype;

Expand All @@ -13,8 +13,19 @@ QUnit.test('AsyncIterator#drop', assert => {

drop.call(createIterator([1, 2, 3]), 1).toArray().then(it => {
assert.arrayEqual(it, [2, 3], 'basic functionality');
async();
});
return drop.call(createIterator([1, 2, 3]), -1).toArray();
}).then(it => {
assert.arrayEqual(it, [1, 2, 3], 'negative');
return drop.call(createIterator([1, 2, 3]), 1.5).toArray();
}).then(it => {
assert.arrayEqual(it, [2, 3], 'float');
return drop.call(createIterator([1, 2, 3]), 4).toArray();
}).then(it => {
assert.arrayEqual(it, [], 'big');
return drop.call(createIterator([1, 2, 3]), 0).toArray();
}).then(it => {
assert.arrayEqual(it, [1, 2, 3], 'zero');
}).then(() => async());

assert.throws(() => drop.call(undefined, 1), TypeError);
assert.throws(() => drop.call(null, 1), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.every.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#every', assert => {
assert.expect(9);
assert.expect(12);
const async = assert.async();
const { every } = AsyncIterator.prototype;

Expand All @@ -16,8 +17,12 @@ QUnit.test('AsyncIterator#every', assert => {
return every.call(createIterator([1, 2, 3]), it => it === 2);
}).then(result => {
assert.ok(!result, 'basic functionality, -');
async();
});
return every.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => async());

assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.filter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#filter', assert => {
assert.expect(8);
assert.expect(11);
const async = assert.async();
const { filter } = AsyncIterator.prototype;

Expand All @@ -13,8 +14,12 @@ QUnit.test('AsyncIterator#filter', assert => {

filter.call(createIterator([1, 2, 3]), it => it % 2).toArray().then(it => {
assert.arrayEqual(it, [1, 3], 'basic functionality');
async();
});
return filter.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
}).then(() => async());

assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.find.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#find', assert => {
assert.expect(9);
assert.expect(12);
const async = assert.async();
const { find } = AsyncIterator.prototype;

Expand All @@ -16,8 +17,12 @@ QUnit.test('AsyncIterator#find', assert => {
return find.call(createIterator([1, 2, 3]), it => it === 4);
}).then(result => {
assert.same(result, undefined, 'basic functionality, -');
async();
});
return find.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => async());

assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.flat-map.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator, createIterable } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#flatMap', assert => {
assert.expect(8);
assert.expect(11);
const async = assert.async();
const { flatMap } = AsyncIterator.prototype;

Expand All @@ -13,8 +14,12 @@ QUnit.test('AsyncIterator#flatMap', assert => {

flatMap.call(createIterator([1, [], 2, createIterable([3, 4]), [5, 6], 'ab']), it => typeof it == 'number' ? -it : it).toArray().then(it => {
assert.arrayEqual(it, [-1, -2, 3, 4, 5, 6, 'ab'], 'basic functionality');
async();
});
return flatMap.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
}).then(() => async());

assert.throws(() => flatMap.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => flatMap.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.for-each.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#forEach', assert => {
assert.expect(8);
assert.expect(11);
const async = assert.async();
const { forEach } = AsyncIterator.prototype;

Expand All @@ -15,8 +16,12 @@ QUnit.test('AsyncIterator#forEach', assert => {

forEach.call(createIterator([1, 2, 3]), it => array.push(it)).then(() => {
assert.arrayEqual(array, [1, 2, 3], 'basic functionality');
async();
});
return forEach.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => async());

assert.throws(() => forEach.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => forEach.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.map.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#map', assert => {
assert.expect(8);
assert.expect(11);
const async = assert.async();
const { map } = AsyncIterator.prototype;

Expand All @@ -13,8 +14,12 @@ QUnit.test('AsyncIterator#map', assert => {

map.call(createIterator([1, 2, 3]), it => it ** 2).toArray().then(it => {
assert.arrayEqual(it, [1, 4, 9], 'basic functionality');
async();
});
return map.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
}).then(() => async());

assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(null, () => { /* empty */ }), TypeError);
Expand Down
12 changes: 9 additions & 3 deletions tests/pure/esnext.async-iterator.reduce.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#reduce', assert => {
assert.expect(8);
assert.expect(12);
const async = assert.async();
const { reduce } = AsyncIterator.prototype;

Expand All @@ -13,8 +14,13 @@ QUnit.test('AsyncIterator#reduce', assert => {

reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1).then(it => {
assert.same(it, 7, 'basic functionality');
async();
});
return reduce.call(createIterator([2]), function (a, b) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 2, 'arguments length');
assert.same(a, 1, 'argument 1');
assert.same(b, 2, 'argument 2');
}, 1);
}).then(() => async());

assert.throws(() => reduce.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => reduce.call(null, () => { /* empty */ }), TypeError);
Expand Down
11 changes: 8 additions & 3 deletions tests/pure/esnext.async-iterator.some.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AsyncIterator from 'core-js-pure/features/async-iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('AsyncIterator#some', assert => {
assert.expect(9);
assert.expect(12);
const async = assert.async();
const { some } = AsyncIterator.prototype;

Expand All @@ -16,8 +17,12 @@ QUnit.test('AsyncIterator#some', assert => {
return some.call(createIterator([1, 2, 3]), it => it === 4);
}).then(result => {
assert.ok(!result, 'basic functionality, -');
async();
});
return some.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
}).then(() => async());

assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(null, () => { /* empty */ }), TypeError);
Expand Down
17 changes: 14 additions & 3 deletions tests/pure/esnext.async-iterator.take.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AsyncIterator from 'core-js-pure/features/async-iterator';
import { createIterator } from '../helpers/helpers';

QUnit.test('AsyncIterator#take', assert => {
assert.expect(8);
assert.expect(12);
const async = assert.async();
const { take } = AsyncIterator.prototype;

Expand All @@ -13,8 +13,19 @@ QUnit.test('AsyncIterator#take', assert => {

take.call(createIterator([1, 2, 3]), 2).toArray().then(it => {
assert.arrayEqual(it, [1, 2], 'basic functionality');
async();
});
return take.call(createIterator([1, 2, 3]), -1).toArray();
}).then(it => {
assert.arrayEqual(it, [], 'negative');
return take.call(createIterator([1, 2, 3]), 1.5).toArray();
}).then(it => {
assert.arrayEqual(it, [1], 'float');
return take.call(createIterator([1, 2, 3]), 4).toArray();
}).then(it => {
assert.arrayEqual(it, [1, 2, 3], 'big');
return take.call(createIterator([1, 2, 3]), 0).toArray();
}).then(it => {
assert.arrayEqual(it, [], 'zero');
}).then(() => async());

assert.throws(() => take.call(undefined, 1), TypeError);
assert.throws(() => take.call(null, 1), TypeError);
Expand Down
4 changes: 4 additions & 0 deletions tests/pure/esnext.iterator.drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ QUnit.test('Iterator#drop', assert => {
assert.nonEnumerable(Iterator.prototype, 'drop');

assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1).toArray(), [2, 3], 'basic functionality');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), -1).toArray(), [1, 2, 3], 'negative');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1.5).toArray(), [2, 3], 'float');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 4).toArray(), [], 'big');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 0).toArray(), [1, 2, 3], 'zero');

assert.throws(() => drop.call(undefined, 1), TypeError);
assert.throws(() => drop.call(null, 1), TypeError);
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.iterator.every.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Iterator from 'core-js-pure/features/iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('Iterator#every', assert => {
const { every } = Iterator.prototype;
Expand All @@ -11,6 +12,11 @@ QUnit.test('Iterator#every', assert => {

assert.ok(every.call(createIterator([1, 2, 3]), it => typeof it == 'number'), 'basic functionality #1');
assert.ok(!every.call(createIterator([1, 2, 3]), it => it % 2), 'basic functionality #2');
every.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});

assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(null, () => { /* empty */ }), TypeError);
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.iterator.filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Iterator from 'core-js-pure/features/iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('Iterator#filter', assert => {
const { filter } = Iterator.prototype;
Expand All @@ -10,6 +11,11 @@ QUnit.test('Iterator#filter', assert => {
assert.nonEnumerable(Iterator.prototype, 'filter');

assert.arrayEqual(filter.call(createIterator([1, 2, 3]), it => it % 2).toArray(), [1, 3], 'basic functionality');
filter.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();

assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.iterator.find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Iterator from 'core-js-pure/features/iterator';

import { createIterator } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('Iterator#find', assert => {
const { find } = Iterator.prototype;
Expand All @@ -10,6 +11,11 @@ QUnit.test('Iterator#find', assert => {
assert.nonEnumerable(Iterator.prototype, 'find');

assert.same(find.call(createIterator([1, 2, 3]), it => !(it % 2)), 2, 'basic functionality');
find.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});

assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(null, () => { /* empty */ }), TypeError);
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.iterator.flat-map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Iterator from 'core-js-pure/features/iterator';

import { createIterator, createIterable } from '../helpers/helpers';
import { STRICT_THIS } from '../helpers/constants';

QUnit.test('Iterator#flatMap', assert => {
const { flatMap } = Iterator.prototype;
Expand All @@ -14,6 +15,11 @@ QUnit.test('Iterator#flatMap', assert => {
[-1, -2, 3, 4, 5, 6, 'ab'],
'basic functionality'
);
flatMap.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();

assert.throws(() => flatMap.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => flatMap.call(null, () => { /* empty */ }), TypeError);
Expand Down
Loading

0 comments on commit 2ab2cc4

Please sign in to comment.