How to use the @loopback/testlab.stubExpressContext function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab 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 strongloop / loopback-next / packages / rest / src / __tests__ / unit / writer.unit.ts View on Github external
function setupResponseMock() {
    const responseMock = stubExpressContext();
    response = responseMock.response;
    observedResponse = responseMock.result;

    // content-type should be undefined since it's not set in the response yet.
    expect(response.getHeader('content-type')).to.eql(undefined);
  }
});
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / trie-router.unit.ts View on Github external
function givenRequest(options?: ShotRequestOptions): Request {
  return stubExpressContext(options).request;
}
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / routing-table.unit.ts View on Github external
function givenRequest(options?: ShotRequestOptions): Request {
    return stubExpressContext(options).request;
  }
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / rest.component.unit.ts View on Github external
}
        }

        class CustomLogger implements Provider {
          value() {
            return (err: Error, statusCode: number, request: Request) => {
              lastLog = `${request.url} ${statusCode} ${err.message}`;
            };
          }
        }

        const app = new Application();
        app.component(CustomRestComponent);
        const server = await app.getServer(RestServer);
        const logError = await server.get(SequenceActions.LOG_ERROR);
        const expressContext = stubExpressContext({url: '/'});
        logError(new Error('test-error'), 400, expressContext.request);

        expect(lastLog).to.equal('/ 400 test-error');
      });
    });