Last active
March 20, 2019 01:19
-
-
Save emmsdan/675d1799df451b21823dc6a8b4cdacc9 to your computer and use it in GitHub Desktop.
test if a user already exists
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 from 'chai'; | |
import chaiHttp from "chai-http"; | |
import { app as server } from './app.js'; | |
// configure chai to send/receive HTTP REQUEST | |
chai.use(chaiHttp); | |
describe("TDD for Users", () => { | |
after(() => { | |
server.close(); | |
}); | |
context("Check if a User already Exist", () => { | |
it("username should exist", (done) => { | |
chai.request(server) | |
.get('api/v1/getuser/emmsdan') | |
.end((error, response) => { | |
response.should.be.status(200); | |
response.should.be.an('object'); | |
done(); | |
}) | |
}) | |
it("user should not exist", (done) => { | |
chai.request(appServer) | |
.get('api/v1/getuser/fakename') | |
.end((error, response) => { | |
response.should.be.status(404); | |
response.should.be.an('string'); | |
done(); | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple and neatly constructed. Noticed a few things:
it
method, it would help if the string you pass into it is easily readable for the developer(s) who will be reading the test descriptions to know what it does. A sample snippet for clarity:describe('TDD for users')
I think my example seems a little wordy though.
In the second case, you asserted that the response returned by chai should be a string but it always returns an object like you did in case 1. I think you wanted to drill down to response.body
Eslint flags accepting a variable or argument you end up not using in your code. e.g. in the end statements, you could prefix the error objects with an underscore i.e. _error.