> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Class: LynxTestingEnv

A pure-JavaScript implementation of the [Lynx Spec](/next/guide/spec.md),
notably the [Element PAPI](/next/api/engine/element-api.md) and [Dual-threaded Model](/next/guide/spec.md#dual-threaded-model) for use with Node.js.

## Example

```ts
import { LynxTestingEnv } from '@lynx-js/testing-environment';
import { JSDOM } from 'jsdom';

const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });

lynxTestingEnv.switchToMainThread();
// use the main thread Element PAPI
const page = __CreatePage('0', 0);
const view = __CreateView(0);
__AppendElement(page, view);

```

## Constructors

### Constructor

> **new LynxTestingEnv**(`env?`: [`LynxEnv`](/next/api/packages/testing-environment/interfaces/LynxEnv.md)): `LynxTestingEnv`

#### Parameters

| Parameter | Type                                                                      |
| --------- | ------------------------------------------------------------------------- |
| `env?`    | [`LynxEnv`](/next/api/packages/testing-environment/interfaces/LynxEnv.md) |

#### Returns

`LynxTestingEnv`

## Properties

### backgroundThread

> **backgroundThread**: [`LynxGlobalThis`](/next/api/packages/testing-environment/interfaces/LynxGlobalThis.md)

The global object for the background thread.

#### Example

```ts
import { LynxTestingEnv } from '@lynx-js/testing-environment';
import { JSDOM } from 'jsdom';

const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });

lynxTestingEnv.switchToBackgroundThread();
// use the background thread global object
globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
```

***

### env

> **env**: [`LynxEnv`](/next/api/packages/testing-environment/interfaces/LynxEnv.md)

***

### mainThread

> **mainThread**: [`LynxGlobalThis`](/next/api/packages/testing-environment/interfaces/LynxGlobalThis.md) & [`ElementTreeGlobals`](/next/api/packages/testing-environment/type-aliases/ElementTreeGlobals.md)

The global object for the main thread.

#### Example

```ts
import { LynxTestingEnv } from '@lynx-js/testing-environment';
import { JSDOM } from 'jsdom';

const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window });

lynxTestingEnv.switchToMainThread();
// use the main thread global object
const page = globalThis.__CreatePage('0', 0);
const view = globalThis.__CreateView(0);
globalThis.__AppendElement(page, view);
```

## Methods

### clearGlobal()

> **clearGlobal**(): `void`

#### Returns

`void`

***

### injectGlobals()

> **injectGlobals**(): `void`

#### Returns

`void`

***

### reset()

> **reset**(): `void`

#### Returns

`void`

***

### switchToBackgroundThread()

> **switchToBackgroundThread**(): `void`

#### Returns

`void`

***

### switchToMainThread()

> **switchToMainThread**(): `void`

#### Returns

`void`
