@ -8,34 +8,34 @@
|
||||
import {ɵresetJitOptions as resetJitOptions} from '@angular/core';
|
||||
|
||||
/**
|
||||
* Wraps a function in a new function which sets up document and HTML for running a test.
|
||||
*
|
||||
* This function is intended to wrap an existing testing function. The wrapper
|
||||
* adds HTML to the `body` element of the `document` and subsequently tears it down.
|
||||
*
|
||||
* This function is intended to be used with `async await` and `Promise`s. If the wrapped
|
||||
* function returns a promise (or is `async`) then the teardown is delayed until that `Promise`
|
||||
* is resolved.
|
||||
*
|
||||
* On `node` this function detects if `document` is present and if not it will create one by
|
||||
* loading `domino` and installing it.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* describe('something', () => {
|
||||
* it('should do something', withBody('<my-app></my-app>', async () => {
|
||||
* const myApp = renderComponent(MyApp);
|
||||
* await whenRendered(myApp);
|
||||
* expect(getRenderedText(myApp)).toEqual('Hello World!');
|
||||
* }));
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param html HTML which should be inserted into `body` of the `document`.
|
||||
* @param blockFn function to wrap. The function can return promise or be `async`.
|
||||
* @publicApi
|
||||
*/
|
||||
* Wraps a function in a new function which sets up document and HTML for running a test.
|
||||
*
|
||||
* This function is intended to wrap an existing testing function. The wrapper
|
||||
* adds HTML to the `body` element of the `document` and subsequently tears it down.
|
||||
*
|
||||
* This function is intended to be used with `async await` and `Promise`s. If the wrapped
|
||||
* function returns a promise (or is `async`) then the teardown is delayed until that `Promise`
|
||||
* is resolved.
|
||||
*
|
||||
* On `node` this function detects if `document` is present and if not it will create one by
|
||||
* loading `domino` and installing it.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* describe('something', () => {
|
||||
* it('should do something', withBody('<my-app></my-app>', async () => {
|
||||
* const myApp = renderComponent(MyApp);
|
||||
* await whenRendered(myApp);
|
||||
* expect(getRenderedText(myApp)).toEqual('Hello World!');
|
||||
* }));
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param html HTML which should be inserted into `body` of the `document`.
|
||||
* @param blockFn function to wrap. The function can return promise or be `async`.
|
||||
* @publicApi
|
||||
*/
|
||||
export function withBody<T extends Function>(html: string, blockFn: T): T {
|
||||
return function(done: DoneFn) {
|
||||
if (typeof blockFn === 'function') {
|
||||
|
Reference in New Issue
Block a user