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) { export function multiline(arr) {
return arr.join("\n"); return arr.join("\n");
} }
export const assertArrayEquals = assert.deepEqual;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
var square = x => x * x; 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 }); 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); 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; 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!'); expect(new Dog().sayHi()).toBe('Hi, I am a dog. WOOF!');
assert.equal(Dog.getName(), 'Animal/Dog'); expect(Dog.getName()).toBe('Animal/Dog');
var count = 0; var count = 0;
var Cat = class extends (function(){ count++; return Animal; })() {}; 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 {}); var Person = (class Person {});
assert.equal(typeof Person, 'function'); expect(typeof Person).toBe('function');
assert.equal( expect((function(){ return (class Person {}); })().name).toBe('Person');
(function(){ return (class Person {}); })().name,
'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); expect(new Multiplier().n).toBe(1);
assert.equal(new Multiplier(6).n, 6); expect(new Multiplier(6).n).toBe(6);
assert.equal(new Multiplier().multiply(), 1); expect(new Multiplier().multiply()).toBe(1);
assert.equal(new Multiplier(2).multiply(3), 6); expect(new Multiplier(2).multiply(3)).toBe(6);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,6 +32,6 @@ class Cat extends Animal {
var cat = new Cat(); 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'; 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'); var mazer = new Person('Mazer', 'Rackham');
assert.equal(mazer.name, 'Mazer Rackham'); expect(mazer.name).toBe('Mazer Rackham');
mazer.name = 'Ender Wiggin'; mazer.name = 'Ender Wiggin';
assert.equal(mazer.firstName, 'Ender'); expect(mazer.firstName).toBe('Ender');
assert.equal(mazer.lastName, 'Wiggin'); expect(mazer.lastName).toBe('Wiggin');
var forLoopProperties = []; var forLoopProperties = [];
for (var key in mazer) { for (var key in mazer) {
forLoopProperties.push(key); 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(); var foo = new Foo();
foo.foo = function() { value = 2; }; foo.foo = function() { value = 2; };
foo.foo(); foo.foo();
assert.equal(value, 2); expect(value).toBe(2);

View File

@ -24,5 +24,5 @@ class ArrayLike {
} }
var joiner = new Joiner(' & '); var joiner = new Joiner(' & ');
assert.equal(joiner.join(4, 5, 6), '4 & 5 & 6'); expect(joiner.join(4, 5, 6)).toBe('4 & 5 & 6');
assert.equal(new ArrayLike('a', 'b')[1], 'b'); 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(); var tripler = new Tripler();
assert.equal(Tripler.triple(), 3); expect(Tripler.triple()).toBe(3);
assert.equal(Tripler.triple(2), 6); expect(Tripler.triple(2)).toBe(6);
assert.equal(tripler.triple, undefined); 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(); var mega = new MegaTripler();
assert.equal(MegaTripler.triple(2), 36); expect(MegaTripler.triple(2)).toBe(36);
assert.equal(mega.triple, undefined); 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 { class Person {
static set DB(value) { 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(); 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; } 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'; var x = 'y';
assert.equal({[x]: function() { return 10; }}.y(), 10); expect({[x]: function() { return 10; }}.y()).toBe(10);
assert.equal({[x + 'y']() { return 10; }}.yy(), 10); expect({[x + 'y']() { return 10; }}.yy()).toBe(10);

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ function makeMultiplier(x=1) {
return (y=1) => x * y; return (y=1) => x * y;
} }
assert.equal(makeMultiplier()(), 1); expect(makeMultiplier()()).toBe(1);
assert.equal(makeMultiplier(2)(3), 6); expect(makeMultiplier(2)(3)).toBe(6);
assert.deepEqual([1, 2, 3].map(makeMultiplier(2)), [2, 4, 6]); expect([1, 2, 3].map(makeMultiplier(2))).toEqual([2, 4, 6]);
assert.deepEqual([undefined, null, 0].map(makeMultiplier(2)), [2, 0, 0]); 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]; 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}; var context = {a: 99};
// use the default parameter // 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 // 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) { function foo(x=5) {
return x; 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 = {}; var context = {};
assert.strictEqual(a.b(), a); expect(a.b()).toBe(a);
assert.strictEqual(a.b.call(context), context); 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); 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); 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); 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]; return [...arguments];
} }
assert.equal(Object.prototype.toString.call(arrayOf()), '[object Array]'); expect(Object.prototype.toString.call(arrayOf())).toBe('[object Array]');
assert.deepEqual(arrayOf(1, 2, 3), [1, 2, 3]); expect(arrayOf(1, 2, 3)).toEqual([1, 2, 3]);

View File

@ -1,3 +1,3 @@
var names = ['Brian', 'Madeline']; var names = ['Brian', 'Madeline'];
assert.deepEqual(['Thomas', ...names], ['Thomas', 'Brian', 'Madeline']); expect(['Thomas', ...names]).toEqual(['Thomas', 'Brian', 'Madeline']);
assert.deepEqual([1, 2, ...[3, 4, 5]], [1, 2, 3, 4, 5]); 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); 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]); 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; 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. // Ensure the expression of the function being initialized is not copied.
assert.deepEqual([1, 2, 3], new (getArray())(...[1, 2, 3])); expect([1, 2, 3]).toEqual(new (getArray())(...[1, 2, 3]));
assert.equal(callCount, 1); 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: // Ensure that the below does not expand to this:
// //
@ -28,8 +28,8 @@ var obj = {
}; };
obj.getSelf().doCall(...[]); obj.getSelf().doCall(...[]);
assert.deepEqual(ops, ['getSelf', 'doCall', obj]); expect(ops).toEqual(['getSelf', 'doCall', obj]);
ops = []; ops = [];
obj['getSelf']().doCall(...[]); 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]; var numbers = [1, 2, 3];
assert.equal(sum(...numbers), 6); expect(sum(...numbers)).toBe(6);

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
function r(strings) { function r(strings) {
assert.equal(strings.raw[0], '\\n'); expect(strings.raw[0]).toBe('\\n');
return strings.raw.join(''); 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}`; 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) { function tag(strings) {
var values = [].slice.call(arguments, 1); var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a'); expect(strings[0]).toBe('a');
assert.equal(strings[1], 'b'); expect(strings[1]).toBe('b');
assert.equal(values[0], 42); expect(values[0]).toBe(42);
return 'whatever'; return 'whatever';
} }
assert.equal(tag `a${ 42 }b`, 'whatever'); expect(tag `a${ 42 }b`).toBe('whatever');
function tagInterpolateFirst(strings) { function tagInterpolateFirst(strings) {
var values = [].slice.call(arguments, 1); var values = [].slice.call(arguments, 1);
assert.equal(strings[0], ''); expect(strings[0]).toBe('');
assert.equal(strings[1], 'b'); expect(strings[1]).toBe('b');
assert.equal(values[0], 42); expect(values[0]).toBe(42);
return 'whatever'; return 'whatever';
} }
assert.equal(tagInterpolateFirst `${ 42 }b`, 'whatever'); expect(tagInterpolateFirst `${ 42 }b`).toBe('whatever');
function tagInterpolateLast(strings) { function tagInterpolateLast(strings) {
var values = [].slice.call(arguments, 1); var values = [].slice.call(arguments, 1);
assert.equal(strings[0], 'a'); expect(strings[0]).toBe('a');
assert.equal(strings[1], ''); expect(strings[1]).toBe('');
assert.equal(values[0], 42); expect(values[0]).toBe(42);
return 'whatever'; 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 // should have a length of 1
assert.equal(Array.prototype.fill.length, 1); expect(Array.prototype.fill).toHaveLength(1);
// should fill from basic case // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // should handle custom object with negative length
//assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1}); //assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1});
// should handle no elements // should handle no elements
assert.deepEqual([].fill(5), []); expect([].fill(5)).toEqual([]);
// should handle bad start // 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 // 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 // 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 // should handle bad this
assert.throws(function() { expect(function() {
Array.prototype.fill.call(null, 5) Array.prototype.fill.call(null, 5)
}, TypeError); }).toThrow(TypeError);

View File

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

View File

@ -1,26 +1,26 @@
// should have a length of 1 // should have a length of 1
assert.equal(Array.prototype.findIndex.length, 1); expect(Array.prototype.findIndex.length).toBe(1);
// should handle basic case // should handle basic case
assert.equal([1, 2, 3].findIndex(function(v) { expect([1, 2, 3].findIndex(function(v) {
return v * v === 4; return v * v === 4;
}), 1); })).toBe(1);
// should handle arrow functions // 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 // 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 // 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 // should handle custom objects
assert.equal(Array.prototype.findIndex.call({ expect(Array.prototype.findIndex.call({
'length': 2, 'length': 2,
'0': false, '0': false,
'1': true '1': true
}, v => v), 1); }, v => v)).toBe(1);
var lengthCalls = 0; var lengthCalls = 0;
var itemCalls = 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++; callbackCalls++;
return v === 'a'; return v === 'a';
}), 2); })).toBe(2);
assert.equal(lengthCalls, 1); expect(lengthCalls).toBe(1);
assert.equal(itemCalls, 1); expect(itemCalls).toBe(1);
assert.equal(callbackCalls, 3); expect(callbackCalls).toBe(3);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
var identity = (identityParam) => identityParam; 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(); var o = new D();
assert.equal(typeof o.x.y, 'function'); expect(typeof o.x.y).toBe('function');
assert.equal(o.x.y(), o); expect(o.x.y()).toBe(o);

View File

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

View File

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

View File

@ -8,11 +8,11 @@ const obj = {
return () => this; return () => this;
} }
}; };
assert.equal(obj.method()(), obj); expect(obj.method()()).toBe(obj);
let fake = {steal: obj.method()}; let fake = {steal: obj.method()};
assert.equal(fake.steal(), obj); expect(fake.steal()).toBe(obj);
let real = {borrow: obj.method}; 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; var value;
async function A() { async function A() {
assert.equal(this, self); expect(this).toBe(self);
var value = await asyncComplete(this, arguments[0]); var value = await asyncComplete(this, arguments[0]);
assert.deepEqual([self, obj], value); expect([self, obj]).toEqual(value);
done(); done();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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