Class AsyncMethodController<WrappingObject, FunctionName>

Controller to be used in tests, that allows for mocking and flushing any asynchronous function. For example, to mock the browser's paste functionality:

 it('can paste', () => {
const clipboard = navigator.clipboard;
const ctx = new AngularContext();

// mock the browser API for pasting
const controller = new AsyncMethodController(clipboard, 'readText');
ctx.run(() => {
// BEGIN production code that copies to the clipboard
let pastedText: string;
clipboard.readText().then((text) => {
pastedText = text;
});
// END production code that copies to the clipboard

controller.expectOne([]).flush('mock clipboard contents');

// BEGIN expect the correct results after a successful copy
expect(pastedText!).toBe('mock clipboard contents');
// END expect the correct results after a successful copy
});
});

Type Parameters

Constructors

Methods