@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
48 lines (32 loc) • 1.82 kB
Markdown
lang: en
title: 'API docs: testlab.testsandbox._constructor_'
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.testsandbox._constructor_.html
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/testlab](./testlab.md) > [TestSandbox](./testlab.testsandbox.md) > [(constructor)](./testlab.testsandbox._constructor_.md)
## TestSandbox.(constructor)
Will create a directory if it doesn't already exist. If it exists, you still get an instance of the TestSandbox.
<b>Signature:</b>
```typescript
constructor(rootPath: string, options?: TestSandboxOptions);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| rootPath | string | Root path of the TestSandbox. If relative it will be resolved against the current directory. |
| options | [TestSandboxOptions](./testlab.testsandboxoptions.md) | Options to control if/how the sandbox creates a subdirectory for the sandbox. If not provided, the sandbox will automatically creates a unique temporary subdirectory. This allows sandboxes with the same root path can be used in parallel during testing. |
## Example
```ts
// Create a sandbox as a unique temporary subdirectory under the rootPath
const sandbox = new TestSandbox(rootPath);
const sandbox = new TestSandbox(rootPath, {subdir: true});
// Create a sandbox in the root path directly
// This is same as the old behavior
const sandbox = new TestSandbox(rootPath, {subdir: false});
// Create a sandbox in the `test1` subdirectory of the root path
const sandbox = new TestSandbox(rootPath, {subdir: 'test1'});
```