🦕 opine-unittest-utils
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.
Getting Started
import { OpineRequest, OpineResponse } from "https://deno.land/x/opine@2.1.2/mod.ts";
import { spy, assertSpyCall} from "https://deno.land/x/mock@0.13.0/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
Installation
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";
Changelog
v0.2
v0.1
Reference
This Deno module is similar to the sinon-express-mock module for express.