Skip to content

Instantly share code, notes, and snippets.

@innocentEdosa
Last active March 21, 2019 08:22
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 innocentEdosa/7c89237b1de5761dbd07a16da6faa071 to your computer and use it in GitHub Desktop.
Save innocentEdosa/7c89237b1de5761dbd07a16da6faa071 to your computer and use it in GitHub Desktop.
Test showing TDD by INNOCENT ILEGBINIJIE
import supertest from 'supertest';
import {should} form 'chai';
import app from './index.js';
const mockUser = {
email: 'awonderfuluser@gmail.com',
username: 'wonderfuluser',
password: 'anotherwonderwonders'}
describe('POST /api/users', () => {
it('should register a new user', async () => {
try {
const result = await server
.post('/api/users')
.send(mockUser);
result.status.should.equal(201);
result.body.should.be.an('object');
result.body.should.have.property('user');
}
catch(err) {
throw err
}
});
});
@Fiyiin
Copy link

Fiyiin commented Mar 21, 2019

Nice work, I like the async function.
on line 18 result.body.should.have.property('user'), are you checking for user or username?

@innocentEdosa
Copy link
Author

innocentEdosa commented Mar 21, 2019

Thanks fiyiin.
The 'user' property is the user object sent in the response Json object

@kayroy247
Copy link

You have done a good job with your test but you may need to add semicolons on lines 23 and 24.

@innocentEdosa
Copy link
Author

Thanks kayroy247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment