1.0.0 • Published 6 years ago
kudy-tester v1.0.0
kudy-tester
For more convenient testing of kudy routes requests.
For example:
import { default as RouteTester } from "kudy-tester";
import {mockRes} from "sinon-express-mock";
import * as chai from 'chai';
import {mockRes} from "sinon-express-mock";
const expect = chai.expect;
import GetPostsRoute from "./router/GetPostsRoute";
const tester = new RouteTester();
it(
'should call correct status code',
tester.test(
new GetPostsRoute(),
{
headers: {
"Authorization": "Bearer XYZ"
}
},
async (res: mockRes.MockRes): Promise<void> => {
expect(res.sendStatus).to.be.calledWith(200);
}
)
);
Parameters:
- route
- Instance of tested route.
- request additional data
- In default request has set only 2 options
method
(from route gettermethod
) andurl
(from route getterfullPath
). You can through this parameter pass other (like headers, authentication etc.)
- In default request has set only 2 options
- test function
- this function should be async or return promise. It will get final response object as first parameter and you can do here all necessary testing stuff.