@s-libs/ng-vitest
    Preparing search index...

    Class AsyncMethodController<WrappingObject, MethodName>

    Controller to be used in tests, that allows for mocking and flushing any asynchronous method. If you are using an AngularContext, it automatically calls AngularContext#tick after each .flush() and .error() to trigger promise handlers and change detection. This is the normal production behavior of asynchronous browser APIs.

    For example, to mock the browser's paste functionality:

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

    // mock the browser API for pasting
    const controller = new AsyncMethodController(clipboard, 'readText');
    await ctx.run(async () => {
    // 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

    await 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

    • WrappingObject extends object
    • MethodName extends AsyncMethodKeys<WrappingObject>

    Hierarchy

    Index

    Constructors

    Methods

    • Verify that no unmatched calls are outstanding.

      If any calls are outstanding, fail with an error message indicating which calls were not handled.

      Returns void