1.0.0 • Published 6 years ago

kudy-tester v1.0.0

Weekly downloads
20
License
MIT
Repository
-
Last release
6 years ago

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 getter method) and url (from route getter fullPath). You can through this parameter pass other (like headers, authentication etc.)
  • 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.