Last active
September 14, 2020 05:23
-
-
Save WhereJuly/176ec66437b73a7378d1395c044e5ffe to your computer and use it in GitHub Desktop.
Mocha test with `async/await` vs `done` approaches
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
'use strict'; | |
const assert = require("assert"); | |
const chai = require("chai"); | |
const chaiHttp = require("chai-http"); | |
const server = require("../src/app"); | |
// See the coupled Express server snippet here | |
// https://gist.github.com/WhereJuly/7b275ec75380505aa9db9a384f0e4ab3 | |
chai.use(chaiHttp); | |
describe('Basic API Testing Example', function() { | |
after(() => server.close()); | |
it('with async/await', async function() { | |
const res = await chai.request(server) | |
.get('/') | |
.send(); | |
assert.equal(res.status, 200); | |
}); | |
it('with done & a callback', (done) => { | |
chai.request(server) | |
.get('/') | |
.end((err, res) => { | |
assert.equal(res.status, 200); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment