Skip to main content

allSettled

allSettled

allSettled<T>(unit: Event<T>, {scope: Scope, params?: T}): Promise<void>
allSettled<T>(unit: Effect<T, Done, Fail>, {scope: Scope, params?: T}): Promise<
| {status: 'done'; value: Done}
| {status: 'fail'; value: Fail}
>
allSettled<T>(unit: Store<T>, {scope: Scope, params?: T}): Promise<void>

Call provided unit in scope and wait for finishing all the triggered effects.

Arguments

  1. unit: Event or Effect to be called
  2. scope: Scope
  3. params: params passed to unit
note

Return value for effect is supported since effector 21.4.0

allSettled(scope)

allSettled<T>(scope): Promise<void>

Check for any ongoing computations in provided scope and wait for their finish.

Arguments

  1. scope: Scope
note

Supported since effector 22.5.0

Example

E.g. tests for integration with some external reactive api

test('integration with externalSource', async () => {
const scope = fork()

const updated = createEvent()

sample({
clock: updated,
target: someOtherLogicStart,
})

// 1. Subscribe event to some external source
const externalUpdated = scopeBind(updated, {scope})
externalSource.listen(() => externalUpdates())

// 2. Trigger update of external source
externalSource.trigger()

//3. Wait for all triggered computations in effector's scope, even though these were not triggered by effector itself
await allSettled(scope)

// 4. Check anything as usual
expect(...).toBe(...)
})