API automation testing framework built on Mocha with Supertest that makes testing API endpoints easy, fast, and fun
supertest-mocha-framework
is a open source api testing framework built on mocha and supertest to make the api testing simple, easy and fun. We continuously working on framework to provide you a seamless experience by adding more and more commandline options and features.
npm i --save supertestmocha
mocha
and supertest
are peer dependencies, you can install explicitly../demo-project
folder for the reference
var config = {
"baseUrl": "https://reqres.in",
"debug": true | false
}
supertestmocha
in your test file or global config file
var supermocha = require('supertestmocha')
var test = new supermocha(config);
test
object to create test casestest.assert
to apply the chaijs assertionoptions
object to test objectCallback
function
var expect = require('chai').expect;
describe('Test Suite...', function () {
this.timeout(18000)
// Example Test Case 01
it('\n1. Create a Test User', function (done) {
test({
uri: '/api/users',
method: 'post',
json: {
"name": "Test User",
"job": "Quality Check"
}
}, function (err, res) {
test.assert(err, res, function () {
expect(res.body).to.have.property('name', 'Test User')
expect(res.body).to.have.property('job', 'Quality Check')
// Add required assertion here
}, done)
})
});
});
test({options}, cb);
uri
, method
, json
, headers
content-type
etc..mocha
as runner: mocha example\use.js -[options]
mocha example\use.js -d
-d
| --debug
to debug the api, it will log the api request and reponse-p
| --parallel
use to run the test cases in parallel-l
| --logs
save the logs in .log file