Created
June 21, 2017 03:13
-
-
Save laktek/0bc93ec22b83c83cbaf19566847a514f 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
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