-
Notifications
You must be signed in to change notification settings - Fork 3
/
promise.test.js
49 lines (38 loc) · 1.26 KB
/
promise.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import test from 'ava';
import argsert from './src/promise';
// NOTE: these examples use the promise API for coverage purposes only, but you
// can use them as documented for either one of the APIs.
test('the arguments object can be passed in, spread', async t => {
function foo() {
return argsert('[string|number] <object>', ...arguments);
}
t.true(await foo('far', {}));
});
test('Function.prototype.apply with the arguments object', async t => {
function foo() {
return argsert(...arguments);
}
t.true(await foo('[string|number] <object>', 'bar', {}));
});
test('allows `this` to be the typeConfig string', async t => {
function foo() {
return argsert.apply('<null|object> [number]', arguments);
}
t.true(await foo({ bar: 'baz' }));
});
test('Function.prototype.call with the arguments object spread', t => {
function foo() {
return argsert.call('[number] <object>', ...arguments);
}
return t.throws(
foo('bar', {}),
/Invalid first argument. Expected number or undefined but received string./
);
});
test('Function.prototype.bind using configurationString', t => {
const foo = argsert.bind('[number]');
return t.throws(
foo({}),
/Invalid first argument. Expected number or undefined but received object./
);
});