Skip to content

Instantly share code, notes, and snippets.

@Joyce-O

Joyce-O/test.js

Last active Mar 21, 2019
Embed
What would you like to do?
Unit test for get tags api endpoint in the medium.com website
describe('Test for get tags endpoint', () => {
it('Should return status code 200 for success', (done) => {
chai.request(app)
.get('/api/tags')
.set('authorization', token)
.end((error, response) => {
expect(response).to.have.status(200);
done();
});
it('should return 404 for tags not found', (done) => {
chai.request(app)
.get('/api/tags')
.set('authorization', token)
.end((error, response) => {
expect(response).to.have.status(404);
expect(response.body.error).to.equal('tags not found');
done();
});
});
});
@innocentEdosa

This comment has been minimized.

Copy link

@innocentEdosa innocentEdosa commented Mar 21, 2019

Hello Joyce,
Nice work. I think you might want to consider using async/await for asynchronous calls because it helps in making code cleaner and also makes error handling easier (try/catch).
Thanks

@kayroy247

This comment has been minimized.

Copy link

@kayroy247 kayroy247 commented Mar 21, 2019

Good job with your test but I think you may need to improve on the following:

  1. Paying attention to details because from the specificaiton, the endpoint to get tags is "/api/tags" and not "/api/v1/tags" you used on line 4.
  2. You used the same endpoint for successfully getting tags on line 4 and also for tags endpoint that does not exist on 12.
  3. The indentation on line 9, 10, 18 and 20 are not consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.