A mechanism for providing dynamically updatable feature flag values to an SDK client in test scenarios.

TestData integrates with the SDK as a plugin and uses the debug override mechanism to inject flag values. Unlike streaming or polling data sources that connect to LaunchDarkly services, TestData lets you define flag values in code and update them during test execution without any network I/O.

Primary use cases:

  • Unit tests that need predictable flag evaluation behavior
  • Integration tests that simulate various flag configurations
  • Local development environments without LaunchDarkly connectivity

Important: TestData is intended exclusively for testing and development scenarios. It must not be used in production environments.

Example

import { TestData } from '@launchdarkly/client-testing-plugin';
import { createClient } from '@launchdarkly/js-client-sdk';

const td = new TestData({
'show-banner': true,
greeting: 'Hello',
});

const client = createClient('test-key', context, {
plugins: [td],
sendEvents: false,
streaming: false,
});
await client.start({ bootstrap: {} });

// Update flag values at any time:
td.setBool('show-banner', false).setString('greeting', 'Welcome');

Hierarchy

  • TestData

Implements

  • LDPluginBase<unknown, unknown>

Constructors

  • Creates a new TestData instance, optionally seeded with a base set of flag values. The seed values are applied to the SDK client when it initializes.

    Parameters

    • Optional initialFlags: {
          [key: string]: LDFlagValue;
      }

      optional map of flag keys to values

      Optional
      • [key: string]: LDFlagValue

    Returns TestData

Properties

_debugOverride?: LDDebugOverride
_values: Record<string, any> = ...

Methods

  • Internal

    Shared write path for the typed setters. Stores the value and, if the SDK client is connected, applies the override. Every write fires setOverride, mirroring a real connection that can re-deliver a flag and fire a change event even when the value is unchanged.

    Parameters

    • key: string
    • value: any

    Returns TestData

  • A given TestData instance must be paired with at most one client. Calling registerDebug a second time throws. The SDK plugin runner catches this throw and logs an error rather than failing initialization, so the second client will silently still work but will not receive subsequent flag updates from this TestData.

    Parameters

    • debugOverride: LDDebugOverride

    Returns void

Generated using TypeDoc