Created
February 7, 2018 14:24
-
-
Save vzaidman/9e538254e7c1e8eb349117c5f6457245 to your computer and use it in GitHub Desktop.
This file contains 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
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