Skip to content

Instantly share code, notes, and snippets.

@svsh227
Created April 16, 2020 11:17
Show Gist options
  • Save svsh227/2cb58570f06782dfefa125d03bb0d84d to your computer and use it in GitHub Desktop.
Save svsh227/2cb58570f06782dfefa125d03bb0d84d to your computer and use it in GitHub Desktop.
# Write the test case: Now it’s time to write the test cases for our both API which is written on above server file. We will use mocha and chai to write the test cases. So lets start to write test case. Create a file with name apitest.js inside test folder ( myApp — -> test — -> apitest.js): Copy below code and paste into your apitest.js:
let chai = require(‘chai’);
let chaiHttp = require(‘chai-http’);
var should = chai.should();
chai.use(chaiHttp);
let server = require(‘../app’);//Our parent block
describe(‘Podcast’, () => {
describe(‘/GET media’, () => {
it(‘it should GET all the podcast’, (done) => {
chai.request(server)
.get(‘/media’)
.end((err, res) => {
(res).should.have.status(200);
(res.body).should.be.a(‘object’);
(res.body.podcasts.length).should.be.eql(1);
done();
});
});
});
describe(‘/GET message’, () => {
it(‘it should GET a message’, (done) => {
chai.request(server)
.get(‘/message’)
.end((err, res) => {
(res).should.have.status(200);
(res.body).should.be.a(‘object’);
done();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment