Created
April 16, 2020 11:17
-
-
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:
This file contains 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
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