Hooks
This API is stable.
Keep hooks separate from your feature specs. Keep them in a separate file, or together with your steps.
Hooks allow you execute code before or after each scenario or step runs. This can be useful for recording and replaying network traffic, taking screenshots at the end of every test, or setting up interceptors to name a few examples.
Scenario hooks
import { beforeScenario, afterScenario } from '@antischematic/leftest'
beforeScenario((scenario) => {
console.log(scenario.name)
})
afterScenario((scenario) => {
console.log(scenario.name)
})
The beforeScenario
and afterScenario
hooks receive a ReadonlyScenario
argument representing the current scenario that is being executed. The afterScenario
hook will always run even if the test fails.
Step hooks
import { beforeStep, afterStep } from '@antischematic/leftest'
beforeStep((scenario) => {
console.log(scenario.name)
})
afterStep((scenario) => {
console.log(scenario.name)
})
The beforeStep
and afterStep
hooks receive a ReadonlyScenario
argument representing the current scenario that is being executed.
Hook execution order
The order of execution for hooks in each scenario are:
beforeScenario
oncebeforeStep
once per stepafterStep
once per stepafterScenario
once
Hooks of the same type are run in the order they are declared.
Avoid writing hooks that depend on the execution order.