sequence
- Type:
{ hooks?: 'stack' | 'list' } - Default:
{ hooks: 'stack' }
Configure the execution order of Rstest lifecycle hooks.
sequence.hooks
- Type:
'stack' | 'list' - Default:
'stack'
Controls the order of hooks within each suite:
'stack':beforeAllandbeforeEachrun in declaration order;afterAllandafterEachrun in reverse declaration order.'list': all four hooks run in declaration order. Use this when migrating from Jest if cleanup depends on hook registration order, such as unmounting components before resetting stores.
For nested suites, beforeEach still runs from parent to child, and afterEach still runs from child to parent.
Cleanup functions returned by beforeEach run after all afterEach hooks; those returned by beforeAll run after the suite's afterAll hooks. They also follow this option: 'stack' runs them in reverse order of their corresponding setup hooks, while 'list' runs them in the same order. For nested beforeEach hooks, this includes cleanup from both parent and child suites.
v0.12.6 fixes an inconsistency where returned cleanup functions ran in setup order while afterEach and afterAll ran in reverse order. Returned cleanup functions now also run in reverse setup order by default. This changes their execution order compared with earlier versions.
This option does not change fixture teardown, onTestFinished, or onTestFailed.