Last active
November 22, 2018 20:25
-
-
Save luqmanoop/acc8d059230910149b6302c9cd9841fb to your computer and use it in GitHub Desktop.
A simple TDD case for a `/cats` endpoint
This file contains hidden or 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
import chai, { expect } from "chai"; | |
import chaiHttp from "chai-http"; | |
import server from "../server"; | |
chai.use(chaiHttp); | |
const ENDPOINT = "/api/v1/cats"; | |
let request = null; | |
describe("/api/v1/cats", () => { | |
before(() => { | |
request = chai.request(server).keepOpen(); | |
}); | |
after(() => request.close()); | |
describe("GET /", () => { | |
it("should respond with an array of cats", done => { | |
request.get(ENDPOINT).then(res => { | |
expect(res.body).to.be.an("array").that.is.not.empty; | |
done(); | |
}); | |
}); | |
}); | |
}); |
Good job. Your explanations made it easier to understand.
Superb one, @codeshifu.
Thanks for providing clarity with the comment, too. 🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keeps server connection open/close (to aid multiple requests) using Mocha
before
/after
hooks.so instead of doing this for every request in all test suite
we have this instead
The test verifies that the endpoint responds with an array of cats