Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- })
Add Comment
Please, Sign In to add comment