Deno module provides simple mock objects for requests and responses to facilitate unit testing for Opine.
Compared to the Deno module SuperDeno, here the handler can be tested independently from the Opine App instance by calling them directly with mocked request and response objects.
import { OpineRequest, OpineResponse } from "https://deno.land/x/[email protected]/mod.ts";
import { spy, assertSpyCall} from "https://deno.land/x/[email protected]/mod.ts";
import { mockRequest, mockResponse } from "https://deno.land/x/opine_unittest_utils";
function opineRequestHandler(req: OpineRequest, res: OpineResponse) {
res.send("message");
}
Deno.test("Simple test with opine-unittest-utils", () => {
const request = mockRequest();
const response = mockResponse();
opineRequestHandler(request, response);
assertSpyCall(response.send as Spy<any>, 0, { args: ["message"] });
});
Further Examples in examples
This is a Deno module available to import direct from this repo and via the Deno Registry.
Before importing, download and install Deno.
You can then import opine-unittest-utils
straight into your project:
import { opine-unittest-utils } from "https://deno.land/x/opine_unittest_utils/mod.ts";
This Deno module is similar to the sinon-express-mock module for express.