diff --git a/test/unit/browser/wd-bluebird.js b/test/unit/browser/wd-bluebird.js new file mode 100644 index 000000000..f13a3682b --- /dev/null +++ b/test/unit/browser/wd-bluebird.js @@ -0,0 +1,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() + ); + }); +});