How to use the node-mocks-http.createMocks function in node-mocks-http

To help you get started, we’ve selected a few node-mocks-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github untool / untool / packages / express / lib / render.js View on Github external
new Promise((resolve, reject) => {
    const allOptions = typeof options === 'string' ? { url: options } : options;
    const { locals = {}, ...reqOptions } = allOptions;
    const resOptions = { eventEmitter, locals };

    const { req, res } = createMocks(reqOptions, resOptions);

    req.mock = res.mock = true;

    res.on('finish', () => {
      if (res.statusCode !== 200) {
        reject(new Error(`Received status ${res.statusCode} for: ${req.url}`));
      } else {
        resolve(res._getData());
      }
    });

    app.handle(req, res, (error) => {
      reject(error || new Error(`Can't get response for: ${req.url}`));
    });
  });

node-mocks-http

Mock 'http' objects for testing Express, Next.js and Koa routing functions

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis