Instantiate a @salesforce/core test context.

Constructors

  • Parameters

    • options: {
          sandbox?: SinonSandbox;
          setup?: boolean;
          sinon?: SinonStatic;
      } = {}
      • Optional sandbox?: SinonSandbox
      • Optional setup?: boolean
      • Optional sinon?: SinonStatic

    Returns TestContext

Properties

SANDBOX: SinonSandbox

The default sandbox is cleared out before each test run.

See [sinon sandbox]https://sinonjs.org/releases/v14/sandbox/.

SANDBOXES: SandboxTypes

An object of different sandboxes. Used when needing to restore parts of the system for customized testing.

TEST_LOGGER: Logger

The test logger that is used when Logger.child is used anywhere. It uses memory logging.

configStubs: {
    AuthInfoConfig?: ConfigStub;
    Config?: ConfigStub;
    OrgUsersConfig?: ConfigStub;
    SfProjectJson?: ConfigStub;
    [configName: string]: Optional<ConfigStub>;
} = {}

An object used in tests that interact with config files.

Type declaration

id: string = ...

id A unique id for the test run.

stubs: Record<string, SinonStub<any[], any>> = {}

A record of stubs created during instantiation.

Methods

  • Used to mock http request to Salesforce.

    Parameters

    • request: AnyJson

      An HttpRequest.

    • Optional options: AnyJson

      Additional options.

      See Connection.request

    Returns Promise<AnyJson>

  • Gets a config stub contents by name.

    Parameters

    • name: string

      The name of the config.

    • Optional group: string

      If the config supports groups.

    Returns ConfigContents

  • A function used when resolving the global path. Calls globalPathResolverSync by default.

    Parameters

    • uid: string

      Unique id.

    Returns Promise<string>

  • A function used when resolving the global path.

    Parameters

    • uid: string

      Unique id.

    Returns string

  • Set stubs for working in the context of a SfProject

    Parameters

    • inProject: boolean = true

    Returns void

  • A function used when resolving the local path. Calls localPathResolverSync by default.

    Parameters

    • uid: string

      Unique id.

    Returns Promise<string>

  • A function used when resolving the local path.

    Parameters

    • uid: string

      Unique id.

    Returns string

  • A function used for resolving paths. Calls localPathRetriever and globalPathRetriever.

    Parameters

    • isGlobal: boolean

      true if the config is global.

    • Optional uid: string

      user id.

    Returns Promise<string>

  • A function used for resolving paths. Calls localPathRetrieverSync and globalPathRetrieverSync.

    Parameters

    • isGlobal: boolean

      true if the config is global.

    • Optional uid: string

      user id.

    Returns string

  • Sets a config stub contents by name

    Parameters

    • name: string

      The name of the config stub.

    • value: ConfigContents

      The actual stub contents. The Mock data.

    Returns void

  • Add beforeEach and afterEach hooks to init the stubs and restore them. This is called automatically when the class is instantiated unless the setup option is set to false.

    Returns void

  • Stub the aliases in the global aliases config file.

    Parameters

    • aliases: Record<string, string>
    • group: string = aliasAccessorEntireFile.DEFAULT_GROUP

    Returns void

  • Stub contents in the config file.

    Parameters

    • config: Record<string, string>

    Returns Promise<void>

  • Stub salesforce user authorizations.

    Parameters

    • users: Record<string, MockTestOrgData[]>

      The users to stub. The key is the username of the admin user and it must be included in the users array in order to obtain the orgId key for the remaining users. The admin user is excluded from the users array.

    Returns void