Last active
December 12, 2016 17:22
-
-
Save thiagoa/7521a826905f5d616406090a0041236b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// spec/javascripts/integration/twitter/fetchTimeline.spec.js | |
import { expect } from 'chai'; | |
import sinon from 'sinon'; | |
import fetchTimeline from 'app/twitter/fetchTimeline'; | |
import createFakeTimelineServer from '../../support/createFakeTimelineServer'; | |
describe('fetchTimeline', () => { | |
let server; | |
beforeEach(() => { server = createFakeTimelineServer(); }); | |
afterEach(() => { server.restore(); }); | |
const response = { tweets: [{ text: 'Hi!' }] }; | |
context('when timeline response is ok', () => { | |
it('runs only the then callback', () => { | |
server.stubGet('/twitter_timeline/thiagoaraujos', { status: 200, body: response }); | |
const promise = fetchTimeline('thiagoaraujos').catch(() => 'notMe'); | |
return promise.then((body) => { | |
expect(body).to.deep.equal(response); | |
}); | |
}); | |
it('chains then callbacks', () => { | |
server.stubGet('/twitter_timeline/thiagoaraujos', { status: 200, body: response }); | |
const promise = fetchTimeline('thiagoaraujos').then((body) => { | |
expect(body).to.deep.equal(response); | |
return `${body.tweets[0].text} modified`; | |
}); | |
return promise.then((modifiedBody) => { | |
expect(modifiedBody).to.equal('Hi! modified'); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment