@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
96 lines (76 loc) • 6.33 kB
Markdown
---
lang: en
title: 'API docs: testlab'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/testlab
permalink: /doc/en/lb4/apidocs.testlab.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/testlab](./testlab.md)
## testlab package
A collection of test utilities we use to write LoopBack tests.
## Remarks
Test utilities to help write LoopBack 4 tests:
- `expect` - behavior-driven development (BDD) style assertions - `sinon` - test spies: functions recording arguments and other information for all of their calls - stubs: functions (spies) with pre-programmed behavior - mocks: fake methods (like spies) with pre-programmed behavior (like stubs) as well as pre-programmed expectations - Helpers for creating `supertest` clients for LoopBack applications - HTTP request/response stubs for writing tests without a listening HTTP server - Swagger/OpenAPI spec validation
## Classes
| Class | Description |
| --- | --- |
| [TestSandbox](./testlab.testsandbox.md) | 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)](./testlab.createclientforhandler.md) | Create a SuperTest client connected to an HTTP server listening on an ephemeral port and calling <code>handler</code> to handle incoming requests. |
| [createRestAppClient(app)](./testlab.createrestappclient.md) | 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)](./testlab.createstubinstance.md) | 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 <code>sinon.createStubInstance</code> 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)](./testlab.createunexpectedhttperrorlogger.md) | Creates a Logger that logs an Error if the HTTP status code is not expected |
| [givenHttpServerConfig(customConfig)](./testlab.givenhttpserverconfig.md) | Create an HTTP-server configuration that works well in test environments. - Ask the operating system to assign a free (ephemeral) port. - Use IPv4 localhost <code>127.0.0.1</code> to avoid known IPv6 issues in Docker-based environments like Travis-CI. - Provide default TLS key & cert when <code>protocol</code> is set to <code>https</code>. |
| [httpGetAsync(urlString, agent)](./testlab.httpgetasync.md) | Async wrapper for making HTTP GET requests |
| [httpsGetAsync(urlString, agent)](./testlab.httpsgetasync.md) | Async wrapper for making HTTPS GET requests |
| [skipIf(skip, verb, name, args)](./testlab.skipif.md) | Helper function for skipping tests when a certain condition is met. |
| [skipOnTravis(verb, name, args)](./testlab.skipontravis.md) | Helper function for skipping tests on Travis CI. |
| [stubExpressContext(requestOptions)](./testlab.stubexpresscontext.md) | |
| [stubHandlerContext(requestOptions)](./testlab.stubhandlercontext.md) | |
| [stubServerRequest(options)](./testlab.stubserverrequest.md) | |
| [stubServerResponse(request, onEnd)](./testlab.stubserverresponse.md) | |
| [toJSON(value)](./testlab.tojson.md) | |
| [toJSON(value)](./testlab.tojson_9.md) | |
| [toJSON(value)](./testlab.tojson_10.md) | |
| [toJSON(value)](./testlab.tojson_11.md) | |
| [toJSON(value)](./testlab.tojson_12.md) | |
| [toJSON(value)](./testlab.tojson_13.md) | |
| [toJSON(value)](./testlab.tojson_14.md) | |
| [toJSON(value)](./testlab.tojson_1.md) | |
| [toJSON(value)](./testlab.tojson_2.md) | |
| [toJSON(value)](./testlab.tojson_3.md) | 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)](./testlab.tojson_4.md) | |
| [toJSON(value)](./testlab.tojson_5.md) | |
| [toJSON(value)](./testlab.tojson_6.md) | |
| [toJSON(value)](./testlab.tojson_7.md) | |
| [toJSON(value)](./testlab.tojson_8.md) | |
| [validateApiSpec(spec)](./testlab.validateapispec.md) | |
## Interfaces
| Interface | Description |
| --- | --- |
| [ExpressContextStub](./testlab.expresscontextstub.md) | |
| [HandlerContextStub](./testlab.handlercontextstub.md) | |
| [HostPort](./testlab.hostport.md) | An object that requires host and port properties |
| [HttpOptions](./testlab.httpoptions.md) | |
| [HttpsOptions](./testlab.httpsoptions.md) | |
| [RestApplicationLike](./testlab.restapplicationlike.md) | |
| [RestServerLike](./testlab.restserverlike.md) | |
| [TestSandboxOptions](./testlab.testsandboxoptions.md) | Options for a test sandbox |
## Variables
| Variable | Description |
| --- | --- |
| [expect](./testlab.expect.md) | |
| [inject](./testlab.inject.md) | |
## Type Aliases
| Type Alias | Description |
| --- | --- |
| [Client](./testlab.client.md) | |
| [ObservedResponse](./testlab.observedresponse.md) | |
| [ShotCallback](./testlab.shotcallback.md) | |
| [ShotResponseCtor](./testlab.shotresponsector.md) | |
| [StubbedInstanceWithSinonAccessor](./testlab.stubbedinstancewithsinonaccessor.md) | |
| [TestDefinition](./testlab.testdefinition.md) | A function defining a new test case or a test suite, e.g. <code>it</code> or <code>describe</code>. |