Skip to content

Instantly share code, notes, and snippets.

@jsatk
Created October 18, 2016 03:06
Show Gist options
  • Select an option

  • Save jsatk/c33e7e16435aa4ab647e1a3f53b4e08a to your computer and use it in GitHub Desktop.

Select an option

Save jsatk/c33e7e16435aa4ab647e1a3f53b4e08a to your computer and use it in GitHub Desktop.
import thirdPartyClient from 'some-third-party-client'
import myApi from '../../src/my-api'
describe('myApi', () => {
describe('Error handling', () => {
const myRejection = {
errorCode: 404,
errorMessage: 'You broke everything',
errorUrl: 'http://coolapp.api.docs/error/404/'
}
beforeEach(() => {
sinon.stub(thirdPartyClient.prototype, 'dingus')
.returns(Promise.reject(myRejection)
})
afterEach(() => thirdPartyClient.prototype.dingus.restore())
it('should be rejected with the correct error object', () => {
const expected = myRejection
return myApi.someMethod()
.then(() => {
const actual = thirdPartyClient.prototype.dingus
return expect(actual).to.be.rejected
.and.to.eventually.deep.equal(expected)
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment