Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Created February 7, 2018 14:24
Show Gist options
  • Save vzaidman/9e538254e7c1e8eb349117c5f6457245 to your computer and use it in GitHub Desktop.
Save vzaidman/9e538254e7c1e8eb349117c5f6457245 to your computer and use it in GitHub Desktop.
it('returns an object containing all users', done => {
// create and configure the fake server to replace the native network call
const server = sinon.createFakeServer()
server.respondWith('GET', '/users', [
200,
{ 'Content-Type': 'application/json' },
'[{ "id": 1, "name": "Gwen" }, { "id": 2, "name": "John" }]'
])
// call a process that includes the network request that we mocked
Users.all()
.done(collection => {
const expectedCollection = [
{ id: 1, name: 'Gwen' },
{ id: 2, name: 'John' }
]
expect(collection.toJSON()).to.eql(expectedCollection)
done()
})
// respond to the request
server.respond()
// remove the fake server
server.restore()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment