Migrate babel-preset-es2015 and -next-target tests to use jest expect

This commit is contained in:
Deven Bansod 2018-03-22 22:54:13 +05:30
parent 0856f89882
commit db42a5d70f
377 changed files with 2905 additions and 2899 deletions

View File

@ -11,5 +11,3 @@ export function assertLacksOwnProperty() {}
export function multiline(arr) {
return arr.join("\n");
}
export const assertArrayEquals = assert.deepEqual;

View File

@ -28,9 +28,5 @@ tests.forEach(function (code) {
});
// Should create mapping
assert.notEqual(
res.map.mappings,
'',
'expected to generate sourcemap for: ' + code
);
expect(res.map.mappings).not.toBe('');;
});

View File

@ -17,6 +17,6 @@ class Bar extends Foo {
new Foo;
new Bar;
assert.equal(targets[0], Foo);
assert.equal(targets[1], Bar);
assert.equal(targets[2], Bar);
expect(targets[0]).toBe(Foo);
expect(targets[1]).toBe(Bar);
expect(targets[2]).toBe(Bar);

View File

@ -9,4 +9,4 @@ class Foo {
new Foo;
assert.equal(targets[0], Foo);
expect(targets[0]).toBe(Foo);

View File

@ -12,5 +12,5 @@ function Bar() {
new Foo;
new Bar();
assert.equal(targets[0], Foo);
assert.equal(targets[1], undefined);
expect(targets[0]).toBe(Foo);
expect(targets[1]).toBeUndefined();

View File

@ -7,4 +7,4 @@ function Foo() {
new Foo;
assert.equal(targets[0], Foo);
expect(targets[0]).toBe(Foo);

View File

@ -8,5 +8,5 @@ function foo() {
foo();
foo.call({});
assert.equal(targets[0], undefined);
assert.equal(targets[1], undefined);
expect(targets[0]).toBeUndefined();
expect(targets[1]).toBeUndefined();

View File

@ -12,4 +12,4 @@ var b = {
Object.setPrototypeOf(b, a);
assert.equal(b.name(), "Suyash Verma");
expect(b.name()).toBe("Suyash Verma");

View File

@ -26,32 +26,12 @@ function makeArgumentsReturner() {
}
// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4)
assert.equal(
makeMultiplier(2, 3)(4),
24,
'ensure `arguments` is hoisted out to the first non-arrow scope'
);
expect(makeMultiplier(2, 3)(4)).toBe(24);
assert.deepEqual(
toArray(1, 2, 3),
[1, 2, 3],
'ensure `arguments` is hoisted out to the first non-arrow scope'
);
expect(toArray(1, 2, 3)).toEqual([1, 2, 3]);
assert.equal(
returnDotArguments({arguments: 1}),
1,
'member accesses with `arguments` property should not be replaced'
);
expect(returnDotArguments({arguments: 1})).toBe(1);
assert.deepEqual(
returnArgumentsObject(),
{arguments: 1},
'object property keys named `arguments` should not be replaced'
);
expect(returnArgumentsObject()).toEqual({arguments: 1});
assert.deepEqual(
makeArgumentsReturner()(1, 2, 3),
[1, 2, 3],
'arguments should not be hoisted from inside non-arrow functions'
);
expect(makeArgumentsReturner()(1, 2, 3)).toEqual([1, 2, 3]);

View File

@ -1,2 +1,2 @@
var empty = () => {};
assert.equal(empty(), undefined);
expect(empty()).toBeUndefined();

View File

@ -8,5 +8,5 @@ var obj = {
}
};
assert.strictEqual(obj.method()()(), obj);
assert.strictEqual(obj.method2()()(), obj);
expect(obj.method()()()).toBe(obj);
expect(obj.method2()()()).toBe(obj);

View File

@ -1,2 +1,2 @@
var square = x => x * x;
assert.equal(square(4), 16);
expect(square(4)).toBe(16);

View File

@ -1,2 +1,2 @@
var keyMaker = val => ({ key: val });
assert.deepEqual(keyMaker(9), { key: 9 });
expect(keyMaker(9)).toEqual({ key: 9 });

View File

@ -4,4 +4,4 @@ var obj = {
}
};
assert.strictEqual(obj.method()(), obj);
expect(obj.method()()).toBe(obj);

View File

@ -1,2 +1,2 @@
var odds = [0, 2, 4].map(v => v + 1);
assert.deepEqual(odds, [1, 3, 5]);
expect(odds).toEqual([1, 3, 5]);

View File

@ -1,2 +1,2 @@
var identity = x => x;
assert.equal(identity(1), 1);
expect(identity(1)).toBe(1);

View File

@ -20,10 +20,10 @@ var Dog = class extends Animal {
}
};
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
assert.equal(Dog.getName(), 'Animal/Dog');
expect(new Dog().sayHi()).toBe('Hi, I am a dog. WOOF!');
expect(Dog.getName()).toBe('Animal/Dog');
var count = 0;
var Cat = class extends (function(){ count++; return Animal; })() {};
assert.equal(count, 1);
expect(count).toBe(1);

View File

@ -18,4 +18,4 @@ class Horse extends Animal {
}
}
assert.equal(new Horse().sayHi(), 'WAT?!');
expect(new Horse().sayHi()).toBe('WAT?!');

View File

@ -1,9 +1,6 @@
var Person = (class Person {});
assert.equal(typeof Person, 'function');
expect(typeof Person).toBe('function');
assert.equal(
(function(){ return (class Person {}); })().name,
'Person'
);
expect((function(){ return (class Person {}); })().name).toBe('Person');
assert.equal(typeof (class {}), 'function');
expect(typeof (class {})).toBe('function');

View File

@ -12,4 +12,4 @@ class Dog extends Animal {
}
}
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
expect(new Dog().sayHi()).toBe('Hi, I am a dog. WOOF!');

View File

@ -8,7 +8,7 @@ class Multiplier {
}
}
assert.equal(new Multiplier().n, 1);
assert.equal(new Multiplier(6).n, 6);
assert.equal(new Multiplier().multiply(), 1);
assert.equal(new Multiplier(2).multiply(3), 6);
expect(new Multiplier().n).toBe(1);
expect(new Multiplier(6).n).toBe(6);
expect(new Multiplier().multiply()).toBe(1);
expect(new Multiplier(2).multiply(3)).toBe(6);

View File

@ -7,4 +7,4 @@ class Person {
var me = new Person();
me.firstName = 'Brian';
me.lastName = 'Donovan';
assert.equal(me.getName(), 'Brian Donovan');
expect(me.getName()).toBe('Brian Donovan');

View File

@ -1,5 +1,5 @@
class Foo {
}
assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor');
assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo');
expect(new Foo().constructor).toBe(Foo);
expect(new Foo() instanceof Foo).toBeTruthy();

View File

@ -16,5 +16,5 @@ for (var key in point) {
keys.push(key);
}
assert.equal(point.toString(), '(1, 2)');
assert.deepEqual(keys.sort(), ['x', 'y']);
expect(point.toString()).toBe('(1, 2)');
expect(keys.sort()).toEqual(['x', 'y']);

View File

@ -11,5 +11,5 @@ class ZeroPoint extends Point {
}
}
assert.equal(new ZeroPoint().x, 0);
assert.equal(new ZeroPoint().y, 0);
expect(new ZeroPoint().x).toBe(0);
expect(new ZeroPoint().y).toBe(0);

View File

@ -1,4 +1,4 @@
class Obj extends null {}
assert.strictEqual(Obj.toString, Function.toString);
assert.strictEqual(new Obj().toString, undefined);
expect(Obj.toString).toBe(Function.toString);
expect(new Obj().toString).toBeUndefined();

View File

@ -32,6 +32,6 @@ class Cat extends Animal {
var cat = new Cat();
assert.equal(cat.sound, 'I am a cat. MEOW!');
expect(cat.sound).toBe('I am a cat. MEOW!');
cat.name = 'Nyan';
assert.equal(cat.name, 'Nyan Cat');
expect(cat.name).toBe('Nyan Cat');

View File

@ -16,13 +16,13 @@ class Person {
}
var mazer = new Person('Mazer', 'Rackham');
assert.equal(mazer.name, 'Mazer Rackham');
expect(mazer.name).toBe('Mazer Rackham');
mazer.name = 'Ender Wiggin';
assert.equal(mazer.firstName, 'Ender');
assert.equal(mazer.lastName, 'Wiggin');
expect(mazer.firstName).toBe('Ender');
expect(mazer.lastName).toBe('Wiggin');
var forLoopProperties = [];
for (var key in mazer) {
forLoopProperties.push(key);
}
assert.ok(forLoopProperties.indexOf('name') === -1, 'getters/setters should be unenumerable');
expect(forLoopProperties).not.toEqual(expect.stringContaining('name'));

View File

@ -4,4 +4,4 @@ class Tripler {
}
}
assert.equal(new Tripler().triple(2), 6);
expect(new Tripler().triple(2)).toBe(6);

View File

@ -9,4 +9,4 @@ class Foo {
var foo = new Foo();
foo.foo = function() { value = 2; };
foo.foo();
assert.equal(value, 2);
expect(value).toBe(2);

View File

@ -24,5 +24,5 @@ class ArrayLike {
}
var joiner = new Joiner(' & ');
assert.equal(joiner.join(4, 5, 6), '4 & 5 & 6');
assert.equal(new ArrayLike('a', 'b')[1], 'b');
expect(joiner.join(4, 5, 6)).toBe('4 & 5 & 6');
expect(new ArrayLike('a', 'b')[1]).toBe('b');

View File

@ -9,4 +9,4 @@ class Point {
}
}
assert.deepEqual(Point.ORIGIN, new Point(0, 0));
expect(Point.ORIGIN).toEqual(new Point(0, 0));

View File

@ -16,15 +16,15 @@ class MegaTripler extends Tripler {
var tripler = new Tripler();
assert.equal(Tripler.triple(), 3);
assert.equal(Tripler.triple(2), 6);
assert.equal(tripler.triple, undefined);
expect(Tripler.triple()).toBe(3);
expect(Tripler.triple(2)).toBe(6);
expect(tripler.triple).toBeUndefined();
assert.equal(Tripler.toString(), '3' + Object.toString.call(Tripler) + '3');
expect(Tripler.toString()).toBe('3' + Object.toString.call(Tripler) + '3');
var mega = new MegaTripler();
assert.equal(MegaTripler.triple(2), 36);
assert.equal(mega.triple, undefined);
expect(MegaTripler.triple(2)).toBe(36);
expect(mega.triple).toBeUndefined();
assert.equal(MegaTripler.toString(), '3' + Object.toString.call(MegaTripler) + '3');
expect(MegaTripler.toString()).toBe('3' + Object.toString.call(MegaTripler) + '3');

View File

@ -1,6 +1,6 @@
class Person {
static set DB(value) {
assert.equal(value, 'mysql');
expect(value).toBe('mysql');
}
}

View File

@ -18,4 +18,4 @@ class Derived extends Base {
}
new Derived().p();
assert.equal(log, '[Derived][Base][OtherBase]');
expect(log).toBe('[Derived][Base][OtherBase]');

View File

@ -5,4 +5,4 @@ var foo = {
set [x](v) { this._y = v; }
};
assert.equal((foo.y = 10, foo.y), 10);
expect((foo.y = 10, foo.y)).toBe(10);

View File

@ -1,3 +1,3 @@
var x = 'y';
assert.equal({[x]: function() { return 10; }}.y(), 10);
assert.equal({[x + 'y']() { return 10; }}.yy(), 10);
expect({[x]: function() { return 10; }}.y()).toBe(10);
expect({[x + 'y']() { return 10; }}.yy()).toBe(10);

View File

@ -1,4 +1,4 @@
var x = 'y';
var foo = {[x]: 10, z: {[x]: 10}};
assert.equal(foo.y + foo.z.y, 20);
assert.equal({[x]: {[x]: {[x]: 10}}}.y.y.y, 10);
expect(foo.y + foo.z.y).toBe(20);
expect({[x]: {[x]: {[x]: 10}}}.y.y.y).toBe(10);

View File

@ -1,3 +1,3 @@
var x = 'y';
assert.equal({[x]: 10}.y, 10);
assert.equal({[x + 'y']: 10}.yy, 10);
expect({[x]: 10}.y).toBe(10);
expect({[x + 'y']: 10}.yy).toBe(10);

View File

@ -1,3 +1,3 @@
assert.equal((function(a){}).length, 1);
assert.equal((function(a=5){}).length, 0);
assert.equal((function(a, b, c=5){}).length, 2);
expect((function(a){})).toHaveLength(1);
expect((function(a=5){})).toHaveLength(0);
expect((function(a, b, c=5){})).toHaveLength(2);

View File

@ -2,7 +2,7 @@ function makeMultiplier(x=1) {
return (y=1) => x * y;
}
assert.equal(makeMultiplier()(), 1);
assert.equal(makeMultiplier(2)(3), 6);
assert.deepEqual([1, 2, 3].map(makeMultiplier(2)), [2, 4, 6]);
assert.deepEqual([undefined, null, 0].map(makeMultiplier(2)), [2, 0, 0]);
expect(makeMultiplier()()).toBe(1);
expect(makeMultiplier(2)(3)).toBe(6);
expect([1, 2, 3].map(makeMultiplier(2))).toEqual([2, 4, 6]);
expect([undefined, null, 0].map(makeMultiplier(2))).toEqual([2, 0, 0]);

View File

@ -2,4 +2,4 @@ function foo(x=5, y=6) {
return [x, y];
}
assert.deepEqual(foo(undefined, null), [5, null]);
expect(foo(undefined, null)).toEqual([5, null]);

View File

@ -5,7 +5,7 @@ function call(fn, context=this) {
var context = {a: 99};
// use the default parameter
assert.strictEqual(call.call(context, function(){ return this.a; }), 99);
expect(call.call(context, function(){ return this.a; })).toBe(99);
// explicitly provide the default parameter value
assert.strictEqual(call(function(){ return this.a; }, context), 99);
expect(call(function(){ return this.a; }, context)).toBe(99);

View File

@ -1,4 +1,4 @@
function foo(x=5) {
return x;
}
assert.equal(foo(), 5);
expect(foo()).toBe(5);

View File

@ -4,4 +4,4 @@ var a = {
}
};
assert.strictEqual(a.echo(1), 1);
expect(a.echo(1)).toBe(1);

View File

@ -5,5 +5,5 @@ var a = {
};
var context = {};
assert.strictEqual(a.b(), a);
assert.strictEqual(a.b.call(context), context);
expect(a.b()).toBe(a);
expect(a.b.call(context)).toBe(context);

View File

@ -4,4 +4,4 @@ var a = {
}
};
assert.equal(a.b.name, 'b');
expect(a.b.name).toBe('b');

View File

@ -6,4 +6,4 @@ var a = {
}
};
assert.equal(a.b(), 1);
expect(a.b()).toBe(1);

View File

@ -4,4 +4,4 @@ var a = {
}
};
assert.equal(a.b(), 'c');
expect(a.b()).toBe('c');

View File

@ -2,4 +2,4 @@ var join = (joinStr, ...items) => {
return items.join(joinStr);
};
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');
expect(join(' ', 'a', 'b', 'c')).toBe('a b c');

View File

@ -2,4 +2,4 @@ function join(joinStr, ...items) {
return items.join(joinStr);
}
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');
expect(join(' ', 'a', 'b', 'c')).toBe('a b c');

View File

@ -2,4 +2,4 @@ var join = function(joinStr, ...items) {
return items.join(joinStr);
};
assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c');
expect(join(' ', 'a', 'b', 'c')).toBe('a b c');

View File

@ -2,5 +2,5 @@ function arrayOf() {
return [...arguments];
}
assert.equal(Object.prototype.toString.call(arrayOf()), '[object Array]');
assert.deepEqual(arrayOf(1, 2, 3), [1, 2, 3]);
expect(Object.prototype.toString.call(arrayOf())).toBe('[object Array]');
expect(arrayOf(1, 2, 3)).toEqual([1, 2, 3]);

View File

@ -1,3 +1,3 @@
var names = ['Brian', 'Madeline'];
assert.deepEqual(['Thomas', ...names], ['Thomas', 'Brian', 'Madeline']);
assert.deepEqual([1, 2, ...[3, 4, 5]], [1, 2, 3, 4, 5]);
expect(['Thomas', ...names]).toEqual(['Thomas', 'Brian', 'Madeline']);
expect([1, 2, ...[3, 4, 5]]).toEqual([1, 2, 3, 4, 5]);

View File

@ -2,4 +2,4 @@ function sum(...numbers) {
return numbers.reduce(function(sum, n) { return n + sum; }, 0);
}
assert.equal(sum(4, 5, ...[10, 20, 30]), 69);
expect(sum(4, 5, ...[10, 20, 30])).toBe(69);

View File

@ -7,4 +7,4 @@ var object = {
};
object.append(1, 2, ...[3, 4]);
assert.deepEqual(object.list, [1, 2, 3, 4]);
expect(object.list).toEqual([1, 2, 3, 4]);

View File

@ -13,4 +13,4 @@ var obj = {
}
};
assert.deepEqual([3, 2, 1], [...obj]);
expect([3, 2, 1]).toEqual([...obj]);

View File

@ -4,8 +4,8 @@ function getArray() {
return Array;
}
assert.deepEqual([1, 2, 3], new Array(...[1, 2, 3]));
expect([1, 2, 3]).toEqual(new Array(...[1, 2, 3]));
// Ensure the expression of the function being initialized is not copied.
assert.deepEqual([1, 2, 3], new (getArray())(...[1, 2, 3]));
assert.equal(callCount, 1);
expect([1, 2, 3]).toEqual(new (getArray())(...[1, 2, 3]));
expect(callCount).toBe(1);

View File

@ -8,7 +8,7 @@ var MATH = {
}
};
assert.equal(MATH.sum(1, ...[2, 3]), 6);
expect(MATH.sum(1, ...[2, 3])).toBe(6);
// Ensure that the below does not expand to this:
//
@ -28,8 +28,8 @@ var obj = {
};
obj.getSelf().doCall(...[]);
assert.deepEqual(ops, ['getSelf', 'doCall', obj]);
expect(ops).toEqual(['getSelf', 'doCall', obj]);
ops = [];
obj['getSelf']().doCall(...[]);
assert.deepEqual(ops, ['getSelf', 'doCall', obj]);
expect(ops).toEqual(['getSelf', 'doCall', obj]);

View File

@ -3,4 +3,4 @@ function sum(...numbers) {
}
var numbers = [1, 2, 3];
assert.equal(sum(...numbers), 6);
expect(sum(...numbers)).toBe(6);

View File

@ -1,4 +1,4 @@
var s = `a
b
c`;
assert.equal(s, 'a\n b\n c');
expect(s).toBe('a\n b\n c');

View File

@ -1,4 +1 @@
assert.strictEqual(
`a${1}b${`${1+1}c`}3`,
'a1b2c3'
);
expect(`a${1}b${`${1+1}c`}3`).toBe('a1b2c3');

View File

@ -1,2 +1,2 @@
var s = `str`;
assert.equal(s, 'str');
expect(s).toBe('str');

View File

@ -1,6 +1,6 @@
function r(strings) {
assert.equal(strings.raw[0], '\\n');
expect(strings.raw[0]).toBe('\\n');
return strings.raw.join('');
}
assert.equal(r `\n`, '\\n');
expect(r `\n`).toBe('\\n');

View File

@ -1,2 +1,2 @@
var s = `1 + 1 = ${1 + 1}`;
assert.equal(s, '1 + 1 = 2');
expect(s).toBe('1 + 1 = 2');

View File

@ -1,26 +1,26 @@
function tag(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a');
assert.equal(strings[1], 'b');
assert.equal(values[0], 42);
expect(strings[0]).toBe('a');
expect(strings[1]).toBe('b');
expect(values[0]).toBe(42);
return 'whatever';
}
assert.equal(tag `a${ 42 }b`, 'whatever');
expect(tag `a${ 42 }b`).toBe('whatever');
function tagInterpolateFirst(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], '');
assert.equal(strings[1], 'b');
assert.equal(values[0], 42);
expect(strings[0]).toBe('');
expect(strings[1]).toBe('b');
expect(values[0]).toBe(42);
return 'whatever';
}
assert.equal(tagInterpolateFirst `${ 42 }b`, 'whatever');
expect(tagInterpolateFirst `${ 42 }b`).toBe('whatever');
function tagInterpolateLast(strings) {
var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a');
assert.equal(strings[1], '');
assert.equal(values[0], 42);
expect(strings[0]).toBe('a');
expect(strings[1]).toBe('');
expect(values[0]).toBe(42);
return 'whatever';
}
assert.equal(tagInterpolateLast `a${ 42 }`, 'whatever');
expect(tagInterpolateLast `a${ 42 }`).toBe('whatever');

View File

@ -1,47 +1,47 @@
// should have a length of 1
assert.equal(Array.prototype.fill.length, 1);
expect(Array.prototype.fill).toHaveLength(1);
// should fill from basic case
assert.deepEqual([1, 2, 3].fill(5), [5, 5, 5]);
expect([1, 2, 3].fill(5)).toEqual([5, 5, 5]);
// should fill from start
assert.deepEqual([1, 2, 3].fill(5, 1), [1, 5, 5]);
expect([1, 2, 3].fill(5, 1)).toEqual([1, 5, 5]);
// should fill from start to end
assert.deepEqual([1, 2, 3].fill(5, 1, 2), [1, 5, 3]);
expect([1, 2, 3].fill(5, 1, 2)).toEqual([1, 5, 3]);
// should fill from negative start
assert.deepEqual([1, 2, 3].fill(5, -1), [1, 2, 5]);
expect([1, 2, 3].fill(5, -1)).toEqual([1, 2, 5]);
// should fill from negative start to positive end
assert.deepEqual([1, 2, 3].fill(5, -2, 3), [1, 5, 5]);
expect([1, 2, 3].fill(5, -2, 3)).toEqual([1, 5, 5]);
// should fill from negative start to negative end
assert.deepEqual([1, 2, 3].fill(5, -3, -1), [5, 5, 3]);
expect([1, 2, 3].fill(5, -3, -1)).toEqual([5, 5, 3]);
// should fill from positive start to negative end
assert.deepEqual([1, 2, 3].fill(5, 1, -1), [1, 5, 3]);
expect([1, 2, 3].fill(5, 1, -1)).toEqual([1, 5, 3]);
// should fill custom object
assert.deepEqual(Array.prototype.fill.call({'0': 1, 'length': 3}, 5), {'0': 5, '1': 5, '2': 5, 'length': 3});
expect(Array.prototype.fill.call({'0': 1, 'length': 3}, 5)).toEqual({'0': 5, '1': 5, '2': 5, 'length': 3});
// should handle custom object with negative length
//assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1});
// should handle no elements
assert.deepEqual([].fill(5), []);
expect([].fill(5)).toEqual([]);
// should handle bad start
assert.deepEqual([1, 2, 3].fill(5, 'hello'), [5, 5, 5]);
expect([1, 2, 3].fill(5, 'hello')).toEqual([5, 5, 5]);
// should handle bad end
assert.deepEqual([1, 2, 3].fill(5, 1, {}), [1, 2, 3]);
expect([1, 2, 3].fill(5, 1, {})).toEqual([1, 2, 3]);
// should handle bad start and end
assert.deepEqual([1, 2, 3].fill(5, 'hello', {}), [1, 2, 3]);
expect([1, 2, 3].fill(5, 'hello', {})).toEqual([1, 2, 3]);
// should handle bad this
assert.throws(function() {
expect(function() {
Array.prototype.fill.call(null, 5)
}, TypeError);
}).toThrow(TypeError);

View File

@ -1,36 +1,36 @@
// should have a length of 1
assert.equal(Array.prototype.find.length, 1);
expect(Array.prototype.find.length).toBe(1);
// should handle basic case
assert.equal([1, 2, 3].find(function(v) {
expect([1, 2, 3].find(function(v) {
return v * v === 4;
}), 2);
})).toBe(2);
// should handle arrow functions
assert.equal([1, 2, 3].find(v => v * v === 4), 2);
expect([1, 2, 3].find(v => v * v === 4)).toBe(2);
// should return undefined when not found
assert.equal([1, 2, 3].find(v => v > 10), undefined);
expect([1, 2, 3].find(v => v > 10)).toBeUndefined();
// should return first match
assert.equal([2, 2, 3].find(v => v * v === 4), 2);
expect([2, 2, 3].find(v => v * v === 4)).toBe(2);
// should handle custom objects
assert.equal(Array.prototype.find.call({
expect(Array.prototype.find.call({
'length': 2,
'0': false,
'1': true
}, v => v), true);
}, v => v)).toBe(true);
// should handle bad predicate
assert.throws(function() {
expect(function() {
[1, 2, 3].find(1)
}, TypeError);
}).toThrow('TypeError');
// should handle bad this
assert.throws(function() {
expect(function() {
Array.prototype.find.call(null, function() {})
}, TypeError);
}).toThrow('TypeError');
// should correctly handle this
var global = this;
@ -40,25 +40,25 @@ var global = this;
// should be global this
[1, 2, 3].find(function() {
assert.notEqual(this, self);
assert.equal(this, global);
expect(this).not.toBe(self);
expect(this).toBe(global);
});
// should be the same this
[1, 2, 3].find(function() {
assert.equal(this, self);
expect(this).toBe(self);
}, self);
// should not have an effect on arrow functions
[1, 2, 3].find(() => assert.equal(this, self));
[1, 2, 3].find(() => assert.equal(this, self), self);
[1, 2, 3].find(() => expect(this).toBe(self));
[1, 2, 3].find(() => expect(this).toBe(self), self);
// should call with correct args
var arr = [5];
arr.find(function(value, i, object) {
assert.equal(value, 5);
assert.equal(i, 0);
assert.equal(arr, object);
expect(value).toBe(5);
expect(i).toBe(0);
expect(arr).toBe(object);
});
}
}).assert();
@ -79,10 +79,10 @@ var object = {
}
};
assert.equal(Array.prototype.find.call(object, (v) => {
expect(Array.prototype.find.call(object, (v) => {
callbackCalls++;
return v === 'a';
}), 'a');
assert.equal(lengthCalls, 1);
assert.equal(itemCalls, 1);
assert.equal(callbackCalls, 3);
})).toBe('a');
expect(lengthCalls).toBe(1);
expect(itemCalls).toBe(1);
expect(callbackCalls).toBe(3);

View File

@ -1,26 +1,26 @@
// should have a length of 1
assert.equal(Array.prototype.findIndex.length, 1);
expect(Array.prototype.findIndex.length).toBe(1);
// should handle basic case
assert.equal([1, 2, 3].findIndex(function(v) {
expect([1, 2, 3].findIndex(function(v) {
return v * v === 4;
}), 1);
})).toBe(1);
// should handle arrow functions
assert.equal([1, 2, 3].findIndex(v => v * v === 4), 1);
expect([1, 2, 3].findIndex(v => v * v === 4)).toBe(1);
// should return -1 when not found
assert.equal([1, 2, 3].findIndex(v => v > 10), -1);
expect([1, 2, 3].findIndex(v => v > 10)).toBe(-1);
// should return first match
assert.equal([2, 2, 3].findIndex(v => v * v === 4), 0);
expect([2, 2, 3].findIndex(v => v * v === 4)).toBe(0);
// should handle custom objects
assert.equal(Array.prototype.findIndex.call({
expect(Array.prototype.findIndex.call({
'length': 2,
'0': false,
'1': true
}, v => v), 1);
}, v => v)).toBe(1);
var lengthCalls = 0;
var itemCalls = 0;
@ -38,10 +38,10 @@ var object = {
}
};
assert.equal(Array.prototype.findIndex.call(object, (v) => {
expect(Array.prototype.findIndex.call(object, (v) => {
callbackCalls++;
return v === 'a';
}), 2);
assert.equal(lengthCalls, 1);
assert.equal(itemCalls, 1);
assert.equal(callbackCalls, 3);
})).toBe(2);
expect(lengthCalls).toBe(1);
expect(itemCalls).toBe(1);
expect(callbackCalls).toBe(3);

View File

@ -1,5 +1,5 @@
// should have a length of 1
assert.equal(Array.from.length, 1);
expect(Array.from.length).toBe(1);
var arr;
var obj;
@ -9,24 +9,24 @@ function arrayFromArgs() {
}
arr = arrayFromArgs('a', 1);
assert.equal(arr.length, 2);
assert.deepEqual(arr, ['a', 1]);
assert.isTrue(Array.isArray(arr));
expect(arr.length).toBe(2);
expect(arr).toEqual(['a', 1]);
expect(Array.isArray(arr)).toBe(true);
// should handle undefined values
var arrayLike = {0: 'a', 2: 'c', length: 3};
arr = Array.from(arrayLike);
assert.equal(arr.length, 3);
assert.deepEqual(arr, ['a', undefined, 'c']);
assert.isTrue(Array.isArray(arr));
expect(arr.length).toBe(3);
expect(arr).toEqual(['a', undefined, 'c']);
expect(Array.isArray(arr)).toBe(true);
// should use a mapFn
arr = Array.from([{'a': 1}, {'a': 2}], function(item, i) {
return item.a + i;
});
assert.deepEqual(arr, [1, 3]);
expect(arr).toEqual([1, 3]);
// should set this in mapFn
var thisObj = {a: 10};
@ -34,19 +34,19 @@ arr = Array.from([{'a': 1}, {'a': 2}], function(item, i) {
return this.a + item.a + i;
}, thisObj);
assert.deepEqual(arr, [11, 13]);
expect(arr).toEqual([11, 13]);
// should map on array-like object
arr = Array.from({0: {'a': 5}, length: 1}, function(item, i) {
return item.a + i;
});
assert.deepEqual(arr, [5]);
expect(arr).toEqual([5]);
// should throw on bad map fn
assert.throws(function() {
expect(function() {
Array.from([], null)
}, TypeError);
}).toThrow();
// should make from an array-like object
var arrayLikeObj = function(len) {
@ -55,8 +55,8 @@ var arrayLikeObj = function(len) {
arrayLikeObj.from = Array.from;
obj = arrayLikeObj.from(['a', 'b', 'c']);
assert.equal(obj.length, 3);
assert.deepEqual(obj, {0: 'a', 1: 'b', 2: 'c', length: 3});
expect(obj).toHaveLength(3);
expect(obj).toEqual({0: 'a', 1: 'b', 2: 'c', length: 3});
// should make from a non-array iterable
var calledIterator = 0;
@ -77,11 +77,11 @@ it[1] = 'b';
it[2] = 'c';
obj = Array.from(it);
assert.equal(obj.length, 3);
assert.equal(obj[0], 'a');
assert.equal(obj[1], 'b');
assert.equal(obj[2], 'c');
assert.equal(calledIterator, 3);
expect(obj).toHaveLength(3);
expect(obj[0]).toBe('a');
expect(obj[1]).toBe('b');
expect(obj[2]).toBe('c');
expect(calledIterator).toBe(3);
// should make from a sub-classed array
var length = 0;
@ -93,7 +93,7 @@ class MyArray extends Array {
constructor(v) {
super();
constructorCounter++;
assert.isUndefined(v);
expect(v).toBeUndefined();
}
set length(v) {
@ -109,15 +109,15 @@ class MyArray extends Array {
var ma = MyArray.from(['a', 'b']);
assert.instanceOf(ma, MyArray);
assert.equal(constructorCounter, 1);
assert.equal(lengthSetCounter, 1);
assert.equal(lengthGetCounter, 0);
assert.isTrue(ma.hasOwnProperty('0'));
assert.isTrue(ma.hasOwnProperty('1'));
assert.isFalse(ma.hasOwnProperty('length'));
assert.equal(ma[0], 'a');
assert.equal(ma[1], 'b');
assert.equal(ma.length, 2);
expect(constructorCounter).toBe(1);
expect(lengthSetCounter).toBe(1);
expect(lengthGetCounter).toBe(0);
expect(ma).toContain('0');
expect(ma).toContain('1');
expect(ma).not.toContain('length');
expect(ma[0]).toBe('a');
expect(ma[1]).toBe('b');
expect(ma).toHaveLength(2);
// should make from a sub-classed array without iterable
length = 0;
@ -129,7 +129,7 @@ class MyArray2 extends MyArray {
constructor(v) {
super();
constructorCounter++;
assert.equal(v, 2);
expect(v).toBe(2);
}
};
MyArray2.prototype[Symbol.iterator] = undefined;
@ -147,12 +147,12 @@ ma3[0] = 'a';
ma3[1] = 'b';
ma = MyArray2.from(ma3);
assert.instanceOf(ma, MyArray2);
assert.equal(constructorCounter, 2);
assert.equal(lengthSetCounter, 1);
assert.equal(lengthGetCounter, 0);
assert.isTrue(ma.hasOwnProperty('0'));
assert.isTrue(ma.hasOwnProperty('1'));
assert.isFalse(ma.hasOwnProperty('length'));
assert.equal(ma[0], 'a');
assert.equal(ma[1], 'b');
assert.equal(ma.length, 2);
expect(constructorCounter).toBe(2);
expect(lengthSetCounter).toBe(1);
expect(lengthGetCounter).toBe(0);
expect(ma).toContain('0');
expect(ma).toContain('1');
expect(ma).not.toContain('length');
expect(ma[0]).toBe('a');
expect(ma[1]).toBe('b');
expect(ma).toHaveLength(2);

View File

@ -1,25 +1,25 @@
var arr;
// should have a length of 0
assert.equal(Array.of.length, 0);
expect(Array.of.length).toBe(0);
//should return an array from arguments
arr = Array.of(1, 'a', 3);
assert.deepEqual(arr, [1, 'a', 3]);
expect(arr).toEqual([1, 'a', 3]);
//assert.isTrue(arr instanceof Array);
//should work with no arguments
arr = Array.of();
assert.deepEqual(arr, []);
expect(arr).toEqual([]);
//assert.isTrue(arr instanceof Array);
//should work with sub-classed array
class MyArray extends Array {}
arr = MyArray.of(4, 'b');
assert.equal(arr[0], 4);
assert.equal(arr[1], 'b');
assert.equal(arr.length, 2);
expect(arr[0]).toBe(4);
expect(arr[1]).toBe('b');
expect(arr).toHaveLength(2);
//assert.isTrue(arr instanceof MyArray);
//should call with exotic array
@ -29,9 +29,9 @@ class ExoticArray {
}
}
arr = Array.of.call(ExoticArray, 5, 'c', 6, 'd');
assert.equal(arr[0], 5);
assert.equal(arr[1], 'c');
assert.equal(arr[2], 6);
assert.equal(arr[3], 'd');
assert.equal(arr.length, 4);
expect(arr[0]).toBe(5);
expect(arr[1]).toBe('c');
expect(arr[2]).toBe(6);
expect(arr[3]).toBe('d');
expect(arr).toHaveLength(4);
//assert.isTrue(arr instanceof ExoticArray);

View File

@ -3,15 +3,15 @@ var self = {};
function outer() {
var f = () => {
assert.equal(this, self);
expect(this).toBe(self);
var g = () => {
assert.equal(this, self);
expect(this).toBe(self);
};
g();
var h = function() {
assert.equal(this, global);
expect(this).toBe(global);
};
h();
};

View File

@ -3,9 +3,9 @@ var self = {};
function f() {
(() => {
assert.equal(self, this);
assert.equal(1, arguments.length);
assert.equal(42, arguments[0]);
expect(self).toBe(this);
expect(1).toBe(arguments.length);
expect(42).toBe(arguments[0]);
var THIS = 0;
var ARGUMENTS = 1;
@ -22,20 +22,20 @@ function f() {
}
};
assert.equal(object, object.function()[THIS]);
assert.equal(2, object.function('a', 'b')[ARGUMENTS].length);
assert.equal('a', object.function('a', 'b')[ARGUMENTS][0]);
assert.equal('b', object.function('a', 'b')[ARGUMENTS][1]);
expect(object.function()[THIS]).toBe(object);
expect(object.function('a', 'b')[ARGUMENTS]).toHaveLength(2);
expect(object.function('a', 'b')[ARGUMENTS][0]).toBe('a');
expect(object.function('a', 'b')[ARGUMENTS][1]).toBe('b');
assert.equal(object, object.method()[THIS]);
assert.equal(3, object.method('c', 'd', 'e')[ARGUMENTS].length);
assert.equal('c', object.method('c', 'd', 'e')[ARGUMENTS][0]);
assert.equal('d', object.method('c', 'd', 'e')[ARGUMENTS][1]);
assert.equal('e', object.method('c', 'd', 'e')[ARGUMENTS][2]);
expect(object.function()[THIS]).toBe(object);
expect(object.method('c', 'd', 'e')[ARGUMENTS]).toHaveLength(3);
expect(object.method('c', 'd', 'e')[ARGUMENTS][0]).toBe('c');
expect(object.method('c', 'd', 'e')[ARGUMENTS][1]).toBe('d');
expect(object.method('c', 'd', 'e')[ARGUMENTS][2]).toBe('e');
assert.equal(self, object.arrow()[THIS]);
assert.equal(1, object.arrow('f', 'g')[ARGUMENTS].length);
assert.equal(42, object.arrow('f', 'g')[ARGUMENTS][0]);
expect(object.arrow()[THIS]).toBe(self);
expect(object.arrow('f', 'g')[ARGUMENTS]).toHaveLength(1);
expect(object.arrow('f', 'g')[ARGUMENTS][0]).toBe(42);
})();
}

View File

@ -1,6 +1,6 @@
function f() {
var args = (() => arguments)();
assert.equal(args, arguments);
expect(args).toBe(arguments);
}
f();

View File

@ -4,49 +4,49 @@
// http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax
let empty = () => undefined;
assert.equal(empty(), undefined);
expect(empty()).toBe(undefined);
// Expression bodies needs no parentheses or braces
let identity = (x) => x;
assert.equal(identity(empty), empty);
expect(identity(empty)).toBe(empty);
// Object literals needs to be wrapped in parens.
let keyMaker = (val) => ({key: val});
assert.equal(keyMaker(empty).key, empty);
expect(keyMaker(empty).key).toBe(empty);
// => { starts a block.
let emptyBlock = () => {a: 42};
assert.equal(emptyBlock(), undefined);
expect(emptyBlock()).toBe(undefined);
// Nullary arrow function starts with arrow (cannot begin statement)
const preamble = 'hello';
const body = 'world';
let nullary = () => preamble + ': ' + body;
assert.equal('hello: world', nullary());
expect('hello: world').toBe(nullary());
// No need for parens even for lower-precedence expression body
let square = x => x * x;
assert.equal(81, square(9));
expect(81).toBe(square(9));
let oddArray = [];
let array = [2, 3, 4, 5, 6, 7];
array.forEach((v, i) => { if (i & 1) oddArray[i >>> 1] = v; });
assert.equal('3,5,7', oddArray.toString());
expect('3,5,7').toBe(oddArray.toString());
var f = (x = 42) => x;
assert.equal(42, f());
expect(42).toBe(f());
{
let g = (...xs) => xs;
assertArrayEquals([0, 1, true], g(0, 1, true));
expect(g(0, 1, true)).toEqual([0, 1, true]);;
}
var h = (x, ...xs) => xs;
assertArrayEquals([0, 1, true], h(-1, 0, 1, true));
expect(h(-1, 0, 1, true)).toEqual([0, 1, true]);;
assert.equal(typeof (() => {}), 'function');
assert.equal(Object.getPrototypeOf(() => {}), Function.prototype);
expect(typeof (() => {})).toBe('function');
expect(Object.getPrototypeOf(() => {})).toBe(Function.prototype);
var i = ({a = 1}) => a;
assert.equal(i({}), 1);
assert.equal(i({a: 2}), 2);
expect(i({})).toBe(1);
expect(i({a: 2})).toBe(2);

View File

@ -1,2 +1,2 @@
var identity = (identityParam) => identityParam;
assert.equal(1234, identity(1234));
expect(1234).toBe(identity(1234));

View File

@ -15,5 +15,5 @@ class D extends C {
}
var o = new D();
assert.equal(typeof o.x.y, 'function');
assert.equal(o.x.y(), o);
expect(typeof o.x.y).toBe('function');
expect(o.x.y()).toBe(o);

View File

@ -2,14 +2,14 @@
var f1 = implements => implements;
var f2 = implements => { return implements; };
var f3 = (implements) => { return implements; };
assert.equal(1, f1(1));
assert.equal(2, f2(2));
assert.equal(3, f1(3));
expect(1).toBe(f1(1));
expect(2).toBe(f2(2));
expect(3).toBe(f1(3));
var g = ({static}) => static;
assert.equal(4, g({static: 4}));
expect(4).toBe(g({static: 4}));
var h1 = ([protected]) => protected;
var h2 = ([...protected]) => protected[0];
assert.equal(5, h1([5]));
assert.equal(6, h2([6]));
expect(5).toBe(h1([5]));
expect(6).toBe(h2([6]));

View File

@ -4,11 +4,11 @@ var obj = {
var f = (x) => ({[this.name]: x});
var o = f(1);
assert.equal(1, o.x);
expect(1).toBe(o.x);
this.name = 2;
o = f(3);
assert.equal(3, o[2]);
expect(3).toBe(o[2]);
}
};

View File

@ -8,11 +8,11 @@ const obj = {
return () => this;
}
};
assert.equal(obj.method()(), obj);
expect(obj.method()()).toBe(obj);
let fake = {steal: obj.method()};
assert.equal(fake.steal(), obj);
expect(fake.steal()).toBe(obj);
let real = {borrow: obj.method};
assert.equal(real.borrow()(), real);
expect(real.borrow()()).toBe(real);

View File

@ -12,9 +12,9 @@ var obj = {};
var value;
async function A() {
assert.equal(this, self);
expect(this).toBe(self);
var value = await asyncComplete(this, arguments[0]);
assert.deepEqual([self, obj], value);
expect([self, obj]).toEqual(value);
done();
}

View File

@ -4,6 +4,6 @@
var f = async () => 1;
f().then((result) => {
assert.equal(result, 1);
expect(result).toBe(1);
done();
}).catch(done);

View File

@ -4,6 +4,6 @@
var f = async x => x;
f(1).then((result) => {
assert.equal(result, 1);
expect(result).toBe(1);
done();
}).catch(done);

View File

@ -5,10 +5,10 @@ function g() {
var f = async (x = arguments) => [x, arguments];
f().then((result) => {
assert.equal(result[0][0], 1);
assert.equal(result[1][0], 1);
assert.equal(result[0][1], 2);
assert.equal(result[1][1], 2);
expect(result[0][0]).toBe(1);
expect(result[1][0]).toBe(1);
expect(result[0][1]).toBe(2);
expect(result[1][1]).toBe(2);
done();
}).catch(done);
}

View File

@ -5,8 +5,8 @@ function g() {
var f = async (x = this) => [x, this];
var p = {};
f.call(p).then((result) => {
assert.equal(result[0], o);
assert.equal(result[1], o);
expect(result[0]).toBe(o);
expect(result[1]).toBe(o);
done();
}).catch(done);
}

View File

@ -11,18 +11,18 @@ class C {
async test() {
var x = 0;
await asyncTimeout(1);
assert.equal(1, ++x);
expect(1).toBe(++x);
await asyncTimeout(1);
assert.equal(2, ++x);
expect(2).toBe(++x);
C.test();
}
static async test() {
var x = 0;
await asyncTimeout(1);
assert.equal(1, ++x);
expect(1).toBe(++x);
await asyncTimeout(1);
assert.equal(2, ++x);
expect(2).toBe(++x);
done();
}

View File

@ -11,9 +11,9 @@ var object = {
async test() {
var x = 0;
await asyncTimeout(1);
assert.equal(1, ++x);
expect(1).toBe(++x);
await asyncTimeout(1);
assert.equal(2, ++x);
expect(2).toBe(++x);
done();
}
}

View File

@ -7,12 +7,12 @@ function f() {
}
async = 1;
assert.equal(async, 1);
assert.equal(f(), 2);
expect(async).toBe(1);
expect(f()).toBe(2);
async = async
function g() {
}
assert.equal(async, 1);
expect(async).toBe(1);

View File

@ -7,40 +7,40 @@ var f = (x, y) => ({x, y});
(async function() {
var x = await 1;
assert.equal(1, x);
expect(1).toBe(x);
x = await (await 2);
assert.equal(2, x);
expect(2).toBe(x);
x = (await 3, await 4);
assert.equal(4, x);
expect(4).toBe(x);
x = f(await 5, await 6);
assert.deepEqual({x: 5, y: 6}, x);
expect({x: 5, y: 6}).toEqual(x);
x = await f(await 7, await 8);
assert.deepEqual({x: 7, y: 8}, x);
expect({x: 7, y: 8}).toEqual(x);
if (await true) {
x = 9;
} else {
x = 10;
}
assert.equal(9, x);
expect(9).toBe(x);
if (await false) {
x = 11;
} else {
x = 12;
}
assert.equal(12, x);
expect(12).toBe(x);
var j = 0;
for (var i = await 0; (await i) < (await 3); await i++) {
assert.equal(i, j++);
expect(i).toBe(j++);
}
assert.equal(3, j);
expect(3).toBe(j);
var g = (x) => x;
var h = () => 13;
x = await g({z: await h()});
assert.deepEqual({z: 13}, x);
expect({z: 13}).toEqual(x);
done();
})();

View File

@ -11,6 +11,6 @@ function asyncComplete() {
(async function() {
var value = await asyncComplete();
assert.equal('complete', value);
expect('complete').toBe(value);
done();
})();

View File

@ -5,6 +5,6 @@ async function empty() {
}
empty().then((v) => {
assert.isUndefined(v);
expect(v).toBeUndefined();
done();
});
});

View File

@ -9,10 +9,10 @@ assert.instanceOf(asyncFunctionDefault(), Promise);
(async function() {
var x = await asyncFunction();
assert.equal(x, 1);
expect(x).toBe(1);
var y = await asyncFunctionDefault();
assert.equal(y, 2);
expect(y).toBe(2);
done();
})();

View File

@ -15,11 +15,11 @@ async function test() {
} finally {
finallyVisited = true;
}
assert.equal(42, v);
assert.isTrue(finallyVisited);
expect(42).toBe(v);
expect(finallyVisited).toBe(true);
done();
}
test();
assert.isFalse(finallyVisited);
expect(finallyVisited).toBe(false);
resolve(42);

View File

@ -12,10 +12,10 @@ async function test() {
} finally {
finallyVisited = true;
}
assert.isTrue(finallyVisited);
expect(finallyVisited).toBe(true);
done();
}
test();
assert.isFalse(finallyVisited);
expect(finallyVisited).toBe(false);
resolve();

View File

@ -3,9 +3,9 @@
async function f() {
var x = await 1;
assert.equal(x, 1);
expect(x).toBe(1);
x = await undefined;
assert.equal(x, undefined);
expect(x).toBeUndefined();
done();
}

View File

@ -3,5 +3,5 @@
async function f() {
}
assert.equal(Object.getPrototypeOf(f), Function.prototype);
assert.instanceOf(f(), Promise);
expect(Object.getPrototypeOf(f)).toBe(Function.prototype);
expect(f() instanceof Promise).toBe(true);

View File

@ -8,6 +8,6 @@ async function rethrow(x) {
}
rethrow(2).catch((err) => {
assert.equal(err, 2)
expect(err).toBe(2);
done();
});

View File

@ -9,8 +9,8 @@ async function ret(x) {
(async function() {
var v = await ret(4);
assert.equal(v, 2);
expect(v).toBe(2);
v = await ret(0);
assert.equal(v, 3);
expect(v).toBe(3);
done();
})();

View File

@ -23,7 +23,7 @@ function asyncTimeout(ms) {
value = await asyncThrow(1);
fail("shouldn't get here");
} catch (e) {
assert.equal(1, e);
expect(1).toBe(e);
}
done();

View File

@ -10,12 +10,12 @@ function asyncTimeout(ms) {
(async function() {
var x = 0;
await asyncTimeout(1);
assert.equal(1, ++x);
expect(1).toBe(++x);
await asyncTimeout(1);
assert.equal(2, ++x);
expect(2).toBe(++x);
await asyncTimeout(1);
assert.equal(3, ++x);
expect(3).toBe(++x);
await asyncTimeout(1);
assert.equal(4, ++x);
expect(4).toBe(++x);
done();
})();

Some files were not shown because too many files have changed in this diff Show More