Page Contents

Home > @loopback/testlab

testlab package

@loopback/testlab

Classes

Class Description
TestSandbox TestSandbox class provides a convenient way to get a reference to a sandbox folder in which you can perform operations for testing purposes.

Functions

Function Description
createClientForHandler(handler) Create a SuperTest client connected to an HTTP server listening on an ephemeral port and calling handler to handle incoming requests.
createRestAppClient(app) Create a SuperTest client for a running RestApplication instance. It is the responsibility of the caller to ensure that the app is running and to stop the application after all tests are done.
createStubInstance(constructor) Creates a new object with the given functions as the prototype and stubs all implemented functions.Note: The given constructor function is not invoked. See also the stub API.This is a helper method replacing sinon.createStubInstance and working around the limitations of TypeScript and Sinon, where Sinon is not able to list private/protected members in the type definition of the stub instance and therefore the stub instance cannot be assigned to places expecting TType. See also - https://github.com/Microsoft/TypeScript/issues/13543 - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14811
createUnexpectedHttpErrorLogger(expectedStatusCode) Creates a Logger that logs an Error if the HTTP status code is not expected
givenHttpServerConfig(customConfig) Create an HTTP-server configuration that works well in test environments. - Ask the operating system to assign a free (ephemeral) port. - Use IPv4 localhost 127.0.0.1 to avoid known IPv6 issues in Docker-based environments like Travis-CI. - Provide default TLS key & cert when protocol is set to https.
httpGetAsync(urlString) Async wrapper for making HTTP GET requests
httpsGetAsync(urlString) Async wrapper for making HTTPS GET requests
itSkippedOnTravis(expectation, callback) Helper function for skipping tests on Travis env - legacy variant supporting it only.
skipOnTravis(verb, name, args) Helper function for skipping tests on Travis CI.
stubExpressContext(requestOptions)  
stubHandlerContext(requestOptions)  
stubServerRequest(options)  
stubServerResponse(request, onEnd)  
toJSON(value)  
toJSON(value)  
toJSON(value)  
toJSON(value) JSON encoding does not preserve properties that are undefined As a result, deepEqual checks fail because the expected model value contains these undefined property values, while the actual result returned by REST API does not. Use this function to convert a model instance into a data object as returned by REST API
toJSON(value)  
toJSON(value)  
toJSON(value)  
toJSON(value)  
toJSON(value)  
validateApiSpec(spec)  

Interfaces

Interface Description
ExpressContextStub  
HandlerContextStub  
RestApplicationLike  
RestServerLike  
TestContext  
TestFn * LEGACY API FOR BACKWARDS COMPATIBILITY **

Variables

Variable Description
expect  
inject  

Type Aliases

Type Alias Description
Client  
ConfigRetval  
ObservedResponse  
ShotCallback  
ShotResponseCtor  
StubbedInstanceWithSinonAccessor  
TestDefinition A function defining a new test case or a test suite, e.g. it or describe.