deno.land / x / mongoose@6.7.5 / test / helpers / promiseOrCallback.test.js

promiseOrCallback.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
const assert = require('assert');const promiseOrCallback = require('../../lib/helpers/promiseOrCallback');
describe('promiseOrCallback()', () => { const myError = new Error('This is My Error'); const myRes = 'My Res'; const myOtherArg = 'My Other Arg';
describe('apply callback', () => { it('without error', (done) => { promiseOrCallback( (error, arg, otherArg) => { assert.equal(arg, myRes); assert.equal(otherArg, myOtherArg); assert.equal(error, undefined); done(); }, (fn) => { fn(null, myRes, myOtherArg); } ); });
describe('with error', () => { it('without event emitter', (done) => { promiseOrCallback( (error) => { assert.equal(error, myError); done(); }, (fn) => { fn(myError); } ); });
it('with event emitter', (done) => { promiseOrCallback( () => { }, (fn) => { return fn(myError); }, { listeners: () => [1], emit: (eventType, error) => { assert.equal(eventType, 'error'); assert.equal(error, myError); done(); } } ); }); }); });
describe('chain promise', () => { describe('without error', () => { it('two args', (done) => { const promise = promiseOrCallback( null, (fn) => { fn(null, myRes); } ); promise.then((res) => { assert.equal(res, myRes); done(); }); });
it('more args', (done) => { const promise = promiseOrCallback( null, (fn) => { fn(null, myRes, myOtherArg); } ); promise.then((args) => { assert.equal(args[0], myRes); assert.equal(args[1], myOtherArg); done(); }); }); });
describe('with error', () => { it('without event emitter', (done) => { const promise = promiseOrCallback( null, (fn) => { fn(myError); } ); promise.catch((error) => { assert.equal(error, myError); done(); }); });

it('with event emitter', (done) => { const promise = promiseOrCallback( null, (fn) => { return fn(myError); }, { listeners: () => [1], emit: (eventType, error) => { assert.equal(eventType, 'error'); assert.equal(error, myError); } } ); promise.catch((error) => { assert.equal(error, myError); done(); }); }); }); });});
mongoose

Version Info

Tagged at
a year ago