-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathgreenlet.test.js
38 lines (31 loc) · 888 Bytes
/
greenlet.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
import greenlet from 'greenlet';
describe('greenlet', () => {
it('should return an async function', () => {
let g = greenlet( () => 'one' );
expect(g).toEqual(jasmine.any(Function));
expect(g()).toEqual(jasmine.any(Promise));
});
it('should invoke sync functions', async () => {
let foo = greenlet( a => 'foo: '+a );
let ret = await foo('test');
expect(ret).toEqual('foo: test');
});
it('should forward arguments', async () => {
let foo = greenlet(function() {
return {
args: [].slice.call(arguments)
};
});
let ret = await foo('a', 'b', 'c', { position: 4 });
expect(ret).toEqual({
args: ['a', 'b', 'c', { position: 4 }]
});
});
it('should invoke async functions', async () => {
let bar = greenlet( a => new Promise( resolve => {
resolve('bar: '+a);
}));
let ret = await bar('test');
expect(ret).toEqual('bar: test');
});
});