@skyux-sdk/testing
Version:
This library was generated with [Nx](https://nx.dev).
210 lines (202 loc) • 11 kB
TypeScript
import { _SkyA11yAnalyzerConfig, _SkyTestingCheckVisibilityOptions } from '@skyux-sdk/testing/private';
export { _SkyA11yAnalyzer as SkyA11yAnalyzer } from '@skyux-sdk/testing/private';
import { Predicate, DebugElement } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
interface SkyA11yAnalyzerConfig extends _SkyA11yAnalyzerConfig {
}
/**
* Represents options for the `toBeVisible` Jasmine matcher.
*/
interface SkyToBeVisibleOptions extends _SkyTestingCheckVisibilityOptions {
}
/**
* Interface for "asynchronous" custom Sky matchers which cannot be paired with a `.not` operator.
*/
interface SkyAsyncMatchers<T, U> extends jasmine.AsyncMatchers<T, U> {
/**
* Invert the matcher following this `expect`
*/
not: SkyAsyncMatchers<T, U>;
/**
* `expect` an element to be accessible based on Web Content Accessibility
* Guidelines 2.0 (WCAG20) Level A and AA success criteria.
* @param config The configuration settings for overwriting or turning off specific accessibility checks.
* @see https://developer.blackbaud.com/skyux/learn/get-started/advanced/accessibility-unit-tests
*/
toBeAccessible(config?: SkyA11yAnalyzerConfig): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual text to equal the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
*/
toEqualResourceText(name: string, args?: any[]): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual text to equal the text for the expected resource string.
* Uses `SkyLibResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
*/
toEqualLibResourceText(name: string, args?: any[]): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
* @param trimWhitespace [true] Whether or not to trim whitespace from the actual element text before comparison.
*/
toHaveResourceText(name: string, args?: any[], trimWhitespace?: boolean): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyLibResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
* @param trimWhitespace [true] Whether or not to trim whitespace from the actual element text before comparison.
*/
toHaveLibResourceText(name: string, args?: any[], trimWhitespace?: boolean): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares the tokenized element text against the template.
* Essentially this matches any text that has the non-parameterized text of the template in the order of the template,
* regardless of the value of each of the parameters.
* @param name The resource string to fetch from the resource file and compare against.
*/
toMatchResourceTemplate(name: string): Promise<jasmine.CustomMatcherResult>;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyLibResourcesService.getString(name, args)` to fetch the expected resource string
* and compares the tokenized element text against the template.
* Essentially this matches any text that has the non-parameterized text of the template in the order of the template,
* regardless of the value of each of the parameters.
* @param name The resource string to fetch from the resource file and compare against.
*/
toMatchLibResourceTemplate(name: string): Promise<jasmine.CustomMatcherResult>;
}
/**
* Interface for "normal" custom Sky matchers (includes original jasmine matchers).
*/
interface SkyMatchers<T> extends jasmine.Matchers<T> {
/**
* Invert the matcher following this `expect`
*/
not: SkyMatchers<T>;
/**
* `expect` the actual element to be visible.
* Checks elements style display and visibility and bounding box width/height.
*/
toBeVisible(options?: SkyToBeVisibleOptions): void;
/**
* `expect` the actual element to exist.
*/
toExist(): void;
/**
* `expect` the actual element to have the expected css class.
* @param expectedClassName The css class name to check for.
*/
toHaveCssClass(expectedClassName: string): void;
/**
* `expect` the actual element to have the expected style(s).
* @param expectedStyles An object representing the style(s) to check for.
*/
toHaveStyle(expectedStyles: Record<string, string>): void;
/**
* `expect` the actual element to have the expected text.
* @param expectedText The text to check for in the actual element.
* @param trimWhitespace [true] Whether or not to trim whitespace from the actual element text before comparison.
*/
toHaveText(expectedText: string, trimWhitespace?: boolean): void;
/**
* `expect` the actual component to be accessible based on Web Content Accessibility
* Guidelines 2.0 (WCAG20) Level A and AA success criteria.
* @deprecated Use `await expectAsync(element).toBeAccessible()` instead.
* @param callback The callback to execute after accessibility checks run.
* @param config The configuration settings for overwriting or turning off specific accessibility checks.
* @see https://developer.blackbaud.com/skyux/learn/get-started/advanced/accessibility-unit-tests
*/
toBeAccessible(callback?: () => void, config?: SkyA11yAnalyzerConfig): void;
/**
* `expect` the actual text to equal the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @deprecated Use `await expectAsync('Some message.').toEqualResourceText('foo_bar_key')` instead.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
* @param callback The callback to execute when the comparison fails.
*/
toEqualResourceText(name: string, args?: any[], callback?: () => void): void;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares using ===.
* @deprecated Use `await expectAsync(element).toHaveResourceText('foo_bar_key')` instead.
* @param name The resource string to fetch from the resource file and compare against.
* @param args The string replacement arguments for the expected resource string.
* @param trimWhitespace [true] Whether or not to trim whitespace from the actual element text before comparison.
* @param callback The callback to execute when the comparison fails.
*/
toHaveResourceText(name: string, args?: any[], trimWhitespace?: boolean, callback?: () => void): void;
/**
* `expect` the actual element to have the text for the expected resource string.
* Uses `SkyAppResourcesService.getString(name, args)` to fetch the expected resource string
* and compares the tokenized element text against the template.
* Essentially this matches any text that has the non-parameterized text of the template in the order of the template,
* regardless of the value of each of the parameters.
* @deprecated Use `await expectAsync(element).toMatchResourceTemplate('foo_bar_key')` instead.
* @param name The resource string to fetch from the resource file and compare against.
* @param callback The callback to execute when the comparison fails.
*/
toMatchResourceTemplate(name: string, callback?: () => void): void;
}
/**
* Create an expectation for a spec.
* @param actual Actual computed value to test expectations against.
*/
declare function expect<T>(actual: T): SkyMatchers<T>;
/**
* Create an async expectation for a spec.
* @param actual Actual computed value to test expectations against.
*/
declare function expectAsync<T, U>(actual: T | PromiseLike<T>): SkyAsyncMatchers<T, U>;
declare class SkyBy {
static dataSkyId(skyId: string): Predicate<DebugElement>;
}
interface SkyAppTestUtilityDomEventOptions {
bubbles?: boolean;
cancelable?: boolean;
keyboardEventInit?: KeyboardEventInit;
customEventInit?: object;
}
declare class SkyAppTestUtility {
static fireDomEvent(element: EventTarget | null | undefined, eventName: string, options?: SkyAppTestUtilityDomEventOptions): void;
/**
* Returns the inner text content of an element.
*/
static getText(element: any): string | undefined;
/**
* Returns true if the element exists on the page.
*/
static isVisible(element: any): boolean | undefined;
/**
* Sets the value of an input element and triggers its 'input' and 'change' events.
*/
static setInputValue(element: any, value: string): void;
/**
* Returns the URL of an element's background image, if it exists.
*/
static getBackgroundImageUrl(el: any): string | undefined;
/**
* Returns a DebugElement representing a SKY UX component.
* @internal
* @param fixture The ComponentFixture where the SKY UX component resides.
* @param skyTestId The value of the `data-sky-id` property specified on the SKY UX component.
* @param componentSelector The selector name for the SKY UX component (e.g. 'sky-alert').
*/
static getDebugElementByTestId(fixture: ComponentFixture<any>, skyTestId: string, componentSelector: string): DebugElement;
}
export { SkyAppTestUtility, SkyBy, expect, expectAsync };
export type { SkyA11yAnalyzerConfig, SkyAppTestUtilityDomEventOptions, SkyAsyncMatchers, SkyMatchers, SkyToBeVisibleOptions };