Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed Oct 10, 2016
1 parent f7a0edb commit ded8922
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions 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()
);
});
});

0 comments on commit ded8922

Please sign in to comment.