mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
* express compat improve typings and make them compatible with express itself * assert * assert fix
43 lines
967 B
TypeScript
43 lines
967 B
TypeScript
import {
|
|
spy,
|
|
} from "sinon";
|
|
|
|
import {
|
|
RequestHandler,
|
|
} from "express";
|
|
|
|
import {
|
|
mockReq,
|
|
mockRes,
|
|
} from "sinon-express-mock";
|
|
|
|
const handlers: RequestHandler[] = [];
|
|
|
|
handlers.push((req, res, next) => {
|
|
// mock common methods
|
|
res.send(JSON.stringify(req.accepts())).end();
|
|
});
|
|
|
|
handlers.push((req, res, next) => {
|
|
// next is not a part of the package, it has to be mocked manually
|
|
next();
|
|
});
|
|
|
|
handlers.push((req, res, next) => {
|
|
// cookies are not mocked, but it should be working anyway
|
|
res.send(JSON.stringify(req.cookies)).end();
|
|
});
|
|
|
|
for (const handler of handlers) {
|
|
// run the handler, an exception should be thrown on error
|
|
handler(mockReq(), mockRes(), spy());
|
|
}
|
|
|
|
// test req generics
|
|
const req = mockReq({ testMockReq: `test` });
|
|
console.assert(typeof req.testMockReq === "string");
|
|
|
|
// test res generics
|
|
const res = mockRes({ testMockRes: `test` });
|
|
console.assert(typeof res.testMockRes === "string");
|