Skip to content

Instantly share code, notes, and snippets.

@WhereJuly
Last active September 14, 2020 05:23
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 WhereJuly/176ec66437b73a7378d1395c044e5ffe to your computer and use it in GitHub Desktop.
Save WhereJuly/176ec66437b73a7378d1395c044e5ffe to your computer and use it in GitHub Desktop.
Mocha test with `async/await` vs `done` approaches
'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