Skip to content

Commit

Permalink
Merge branch 'master' into rel-v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aoberoi committed Mar 23, 2018
2 parents 7bf45d1 + b3eabbf commit bc36e4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ describe('WebClient', function () {
});
});

describe('when called with bad options', function () {
it('should reject its Promise with TypeError', function (done) {
const results = [
this.client.apiCall('method', 4),
this.client.apiCall('method', 'a string'),
this.client.apiCall('method', false),
];
const caughtErrors = results.map(r => {
assert(isPromise(r));
return r
.then(() => {
// if any of these promises resolve, this test fails
assert(false);
})
.catch((error) => {
// each promise should reject with the right kind of error
assert.instanceOf(error, TypeError);
});
});
Promise.all(caughtErrors)
.then(() => done());
});

it('should return a TypeError to its callback', function (done) {
this.client.apiCall('method', 4, (error) => {
assert.instanceOf(error, TypeError);
done();
});
});
});

// TODO: simulate each of the error types
describe('when the call fails', function () {
beforeEach(function () {
Expand Down
6 changes: 5 additions & 1 deletion src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ export class WebClient extends EventEmitter {

// The following thunk is the actual implementation for this method. It is wrapped so that it can be adapted for
// different executions below.
const implementation = () => {
const implementation = async () => {

if (typeof options === 'string' || typeof options === 'number' || typeof options === 'boolean') {
throw new TypeError(`Expected an options argument but instead received a ${typeof options}`);
}

const requestBody = this.serializeApiCallOptions(Object.assign({ token: this.token }, options));

Expand Down

0 comments on commit bc36e4b

Please sign in to comment.