The configuration for a wrapper factory provider test.
core/testing/helpers/factories/wrapper-factory-provider-test-production.ts
Properties |
|
additionalSpecs |
additionalSpecs:
|
Type: AdditionalWrapperFactoryProviderSpecs
|
Optional |
(Optional) Additional specs that should be run after the automated specs provided by |
expectedToken |
expectedToken:
|
Type: InjectionToken<Wrapper>
|
Optional |
expectedWrapperType |
expectedWrapperType:
|
Type: Type<Wrapper>
|
The type of the wrapper object expected to be produced by the factory. |
mockNative |
mockNative:
|
Type: Native
|
(Optional) The value that will be returned by the simulated |
provider |
provider:
|
Type: FactoryProvider
|
The provider being tested. |
providerName |
providerName:
|
Type: string
|
The name of the provider being tested. This will be shown in the test spec. |
providers |
providers:
|
Type: any[]
|
Optional |
(Optional) Any providers needed for the test in addition to the ones created by setup function. |
setup |
setup:
|
Type: SetupFn
|
The function that will setup the testing environment. |
import { FactoryProvider, InjectionToken, Type } from '@angular/core';
import { Native, Wrapper, WrapperInstance } from '@bespunky/angular-google-maps/core';
import { setupWrapperFactoryProviderTest, WrapperProviderTestConfig } from './setup/wrappers/wrapper-factory-provider-test-setup';
import { produceWrapperFactoryProviderSpecs, AdditionalWrapperFactoryProviderSpecs } from './specs/wrapper-factory-provider-spec-production';
type SetupFn = (provider: FactoryProvider, config: WrapperProviderTestConfig) => Promise<{ producedValue: any }>;
/**
* The configuration for a wrapper factory provider test.
*
* @export
* @interface WrapperFactoryProviderTest
*/
export interface WrapperFactoryProviderTest
{
/** The name of the provider being tested. This will be shown in the test spec. */
providerName : string;
/** The provider being tested. */
provider : FactoryProvider;
/** The function that will setup the testing environment. */
setup : SetupFn;
expectedToken? : InjectionToken<Wrapper>;
/** The type of the wrapper object expected to be produced by the factory. */
expectedWrapperType: Type<Wrapper>;
/**
* (Optional) The value that will be returned by the **simulated** `produceValue` function passed
* to the generator function. Meaning, when the factory returns, this will be the value it produces.
*/
mockNative : Native;
/** (Optional) Any providers needed for the test in addition to the ones created by setup function. */
providers? : any[];
/** (Optional) Additional specs that should be run after the automated specs provided by `produceBrowserWrapperFactoryProviderSpecs()` and `produceNonBrowserWrapperFactoryProviderSpecs()`. */
additionalSpecs? : AdditionalWrapperFactoryProviderSpecs;
}
/**
* Performs setup and spec production for wrapper factory providers.
*
* How:
* Creates a testing section with the provider name using `describe()`, sets up the testing environment using the provided setup function
* and produces native factory provider specs using the `produceWrapperFactoryProviderSpecs()` function.
*
* @export
* @param {WrapperFactoryProviderTest} config The configuration for the test.
*/
export function testWrapperFactoryProviderCore({providerName, provider, setup, expectedToken, expectedWrapperType, mockNative, providers, additionalSpecs }: WrapperFactoryProviderTest)
{
describe(providerName, () =>
{
let producedWrapper: any;
async function runSetup(platform: any)
{
const config: WrapperProviderTestConfig = { platform, native: mockNative, providers };
({ producedValue: producedWrapper } = await setup(provider, config));
}
expectedToken = expectedToken || WrapperInstance;
produceWrapperFactoryProviderSpecs(runSetup, () => provider, () => producedWrapper, () => expectedToken, expectedWrapperType, mockNative, additionalSpecs);
});
}
/**
* Performs setup and spec production for wrapper factory providers using the default `setupWrapperFactoryProviderTest()` as a setup function.
*
* How:
* Creates a testing section with the provider name using `describe()`, sets up the testing environment using the default setup function
* and produces wrapper factory provider specs using the `produceWrapperFactoryProviderSpecs()` function.
*
* @export
* @param {Omit<WrapperFactoryProviderTest, 'setup'>} testConfig The configuration for the test.
*/
export function testWrapperFactoryProvider(testConfig: Omit<WrapperFactoryProviderTest, 'setup'>)
{
const config = { ...testConfig, setup: setupWrapperFactoryProviderTest };
testWrapperFactoryProviderCore(config);
}