Skip to content

Instantly share code, notes, and snippets.

@laktek
Created June 21, 2017 03:13
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 laktek/0bc93ec22b83c83cbaf19566847a514f to your computer and use it in GitHub Desktop.
Save laktek/0bc93ec22b83c83cbaf19566847a514f to your computer and use it in GitHub Desktop.
export default class App {
constructor(userHandler){
this.userHandler = userHandler;
}
async testing(req, res) => {
const { email } = req.body
const r = await this.userHandler.findOne({email})
res.json(r)
}
}
// then in your tests
test('Pass POST v1/users/testing', async t => {
sinon.stub(User, "findOne" () => { /* return an invalid user */ });
const app = new App(User);
const res = await request(app)
.post('/api/v1/users/testing')
.send({
email: 'testing@email.com'
})
t.is(res.status, 400)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment