Skip to content

Commit

Permalink
test: exponential backoff stop method
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Dec 4, 2024
1 parent 601b84e commit 31804c6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/dapp-toolkit/src/helpers/exponential-backoff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ describe('exponential backoff', () => {
})
})

it('should emit error after stop', async () => {
const backoff = ExponentialBackoff({})
const spy = vi.fn()

subscription.add(
backoff.withBackoff$.subscribe((res) => {
spy(res.isOk() ? res.value : res.error)
if (res.isOk()) {
backoff.trigger.next()
}
}),
)

await delayAsync(2000)
backoff.stop()
expect(spy).toHaveBeenCalledWith(0)
expect(spy).toHaveBeenCalledWith({
error: 'stopped',
})
})

afterAll(() => {
subscription.unsubscribe()
})
Expand Down

0 comments on commit 31804c6

Please sign in to comment.