diff --git a/index.ts b/index.ts index d34c603..5d44ce3 100644 --- a/index.ts +++ b/index.ts @@ -89,12 +89,7 @@ export function test(title: string, callback?: TestExecutor void): Group { validator.ensureIsInPlanningPhase(executionPlanState.phase) - const group = createTestGroup( - title, - emitter, - runnerConfig!.refiner, - executionPlanState - ) + const group = createTestGroup(title, emitter, runnerConfig!.refiner, executionPlanState) executionPlanState.group = group /** @@ -133,6 +128,14 @@ export function getActiveTest() { return activeTest } +/** + * Get the test of currently running test or throw an error + */ +export function getActiveTestOrFail() { + if (!activeTest) throw new Error('Cannot access active test outside of a test callback') + return activeTest +} + /** * Make Japa process command line arguments. Later the parsed output * will be used by Japa to compute the configuration