Skip to main content

testing

@prismatic-io/spectral"testing"

This module provides functions to help developers unit test custom components prior to publishing them. For information on unit testing, check out our docs: https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component

Index#

Interfaces#

Functions#

Object literals#

Functions#

Const getAuthorizationMethods#

getAuthorizationMethods(except?: AuthorizationMethod[]): AuthorizationMethod[]

Defined in testing.ts:33

Get an array of available authorization methods that a custom component can use.

Parameters:

NameTypeDescription
except?AuthorizationMethod[]Return authorization methods except for those in this array.

Returns: AuthorizationMethod[]

This function returns an array of available authorization methods.


Const invoke#

invokeT, AllowsBranching, ReturnData›(actionBase: ActionDefinition‹T, AllowsBranching, ReturnData› | Record‹string, ActionDefinition‹T, AllowsBranching, ReturnData››, params: ActionInputParameters‹T›, context?: Partial‹ActionContext›): Promise‹InvokeReturn‹ReturnData››

Defined in testing.ts:131

Invokes specified ActionDefinition perform function using supplied params and optional context. Accepts a generic type matching PerformReturn as a convenience to avoid extra casting within test methods. Returns an InvokeResult containing both the action result and a mock logger for asserting logging.

Type parameters:

T: Inputs

AllowsBranching: boolean

ReturnData: PerformReturn‹AllowsBranching, unknown›

Parameters:

NameType
actionBaseActionDefinition‹T, AllowsBranching, ReturnData› | Record‹string, ActionDefinition‹T, AllowsBranching, ReturnData››
paramsActionInputParameters‹T›
context?Partial‹ActionContext

Returns: Promise‹InvokeReturn‹ReturnData››


Const loggerMock#

loggerMock(): ActionLogger

Defined in testing.ts:109

Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected. See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.

Returns: ActionLogger

Object literals#

Const credentials#

credentials: object#

Defined in testing.ts:43

Utility functions to generate the different types of Credentials for testing.

apiKey#

apiKey(key: string): ApiKeyCredential

Defined in testing.ts:53

Return a ApiKeyCredential assembled from provided key.

Parameters:

NameType
keystring

Returns: ApiKeyCredential

apiKeySecret#

apiKeySecret(key: string, secret: string): ApiKeySecretCredential

Defined in testing.ts:58

Return a ApiKeySecretCredential assembled from provided key and secret.

Parameters:

NameType
keystring
secretstring

Returns: ApiKeySecretCredential

basic#

basic(username: string, password: string): BasicCredential

Defined in testing.ts:45

Return a BasicCredential assembled from provided username and password.

Parameters:

NameType
usernamestring
passwordstring

Returns: BasicCredential

generate#

generate(method: AuthorizationMethod): Credential

Defined in testing.ts:98

Returns an arbitrary Credential using method. Generally used for testing negative support cases.

Parameters:

NameType
methodAuthorizationMethod

Returns: Credential

oauth2#

oauth2(token: string, redirectUri: string): OAuth2Credential

Defined in testing.ts:74

Return a OAuth2Credential assembled from provided token and optional redirectUri.

Parameters:

NameTypeDefault
tokenstring-
redirectUristring""

Returns: OAuth2Credential

oauth2ClientCredentials#

oauth2ClientCredentials(token: string): OAuth2Credential

Defined in testing.ts:86

Return a OAuth2Credential assembled from provided token.

Parameters:

NameType
tokenstring

Returns: OAuth2Credential

privateKey#

privateKey(username: string, privateKey: string): PrivateKeyCredential

Defined in testing.ts:66

Return a PrivateKeyCredential assembled from provided username and privateKey.

Parameters:

NameType
usernamestring
privateKeystring

Returns: PrivateKeyCredential