Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. it('returns an object containing all users', done => {
  2.  
  3. // create and configure the fake server to replace the native network call
  4. const server = sinon.createFakeServer()
  5. server.respondWith('GET', '/users', [
  6. 200,
  7. { 'Content-Type': 'application/json' },
  8. '[{ "id": 1, "name": "Gwen" }, { "id": 2, "name": "John" }]'
  9. ])
  10.  
  11. // call a process that includes the network request that we mocked
  12. Users.all()
  13. .done(collection => {
  14. const expectedCollection = [
  15. { id: 1, name: 'Gwen' },
  16. { id: 2, name: 'John' }
  17. ]
  18. expect(collection.toJSON()).to.eql(expectedCollection)
  19. done()
  20. })
  21.  
  22. // respond to the request
  23. server.respond()
  24.  
  25. // remove the fake server
  26. server.restore()
  27. })
Add Comment
Please, Sign In to add comment