core3-utils

@wixc3/testing on Github

Home > @wixc3/testing > initAndDisposeAfter

initAndDisposeAfter() function

Warning: This API is now obsolete.

just call init and add to test disposables Runs target.init and disposes of it after the test is done *

Signature:

export declare function initAndDisposeAfter<T extends (...args: any[]) => any>(target: {
    init: T;
} & DisposableItem, options: string | Omit<DisposableOptions, 'dispose'>, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;

Parameters

Parameter Type Description
target { init: T; } & [DisposableItem](/core3-utils/patterns.disposableitem.html)
options string \| Omit<[DisposableOptions](/core3-utils/patterns.disposableoptions.html), 'dispose'>
args Parameters<T>

Returns:

Promise<Awaited<ReturnType<T>>>

init result

Example

it('test', async () => {
     const myService = {
        init: (a:string) => {console.log(a)},
        dispose: () => {console.log('disposed')}
     }
     await initAndDisposeAfter(myService, 'hello') // logs 'hello'
})
// logs 'disposed' after the test is done