Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Last active February 1, 2019 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vzaidman/919b6e17e0f1a1203c89e7a16be2cdca to your computer and use it in GitHub Desktop.
Save vzaidman/919b6e17e0f1a1203c89e7a16be2cdca to your computer and use it in GitHub Desktop.
// make sure User.fetch to respond with a mocked user
// instead of making an actual ajax request
const stub = sinon
.stub(Users.prototype, 'fetch')
.resolves([
{ id: 0, name: 'David', score: 0 },
{ id: 1, name: 'Adam', score: 20 }
])
it('Should add score to a user', done => {
Users.fetchOne({id: 0})
.then(user => {
const userAfterVictory = recordVictory(user)
expect(userAfterVictory.score).toBe(user.score + 10)
done()
})
})
it('Should find a user with the highest score', done => {
Users.fetch()
.then(users => {
const userWithHighestScore = findUserWithHighestScore(users)
expect(userWithHighestScore.score).toBe(20)
done()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment