I am using mocha/chai as a JS testing library for some node code. I am trying to write unit tests for a helper function that accepts a KoaContext.
The function signature looks like this:
export const q2m = (ctx: KoaContext, opts: Q2mOptions = {})
My Mocha test looks like this:
it('should handle an empty query string', function () {
const ctx: KoaContext = {};
const result = q2m(ctx, {});
const expectation: Q2mMongoQuery = {
rawQuery: ctx.request.query,
filters: {},
page: 1,
limit: 25,
skip: 0,
search: null,
sortField: null,
sortDirection: 'ASC',
};
assert.deepEqual(result, expectation);
});
However, typescript complains that ctx does not have all the defined properties of KoaContext. There are nearly 50+ and I dont think it makes sense to define all of those. Is there a way to mock the context so I can unit test my methods?