This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
/
wd-bluebird.js
69 lines (55 loc) 路 1.61 KB
/
wd-bluebird.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
'use strict';
const Promise = require('bluebird');
const q = require('bluebird-q');
const proxyquire = require('proxyquire');
describe('wd-bluebird', () => {
let sandbox, original, wrapped;
beforeEach(() => {
original = {
promiseMethod: () => q('result'),
emit() {},
property: 'value'
};
const wd = proxyquire('lib/browser/wd-bluebird', {
wd: {
promiseRemote: () => original
}
});
wrapped = wd.promiseRemote();
sandbox = sinon.sandbox.create();
});
afterEach(() => {
sandbox.restore();
});
it('should cast original promise to Blubird', () => {
assert.instanceOf(
wrapped.promiseMethod(),
Promise
);
});
it('should resolve to original value', () => {
return assert.eventually.equal(
wrapped.promiseMethod(),
original.promiseMethod()
);
});
it('should forward all arguments to original method', () => {
const arg = 'arg';
sandbox.spy(original, 'promiseMethod');
wrapped.promiseMethod(arg);
assert.calledWith(original.promiseMethod, arg);
});
it('should copy properties as is', () => {
assert.equal(wrapped.property, original.property);
});
it('should not cast event emitter methods results', () => {
assert.isUndefined(
wrapped.emit('event')
);
});
it('should not cast Object.prototype methods results', () => {
assert.isString(
wrapped.toString()
);
});
});