From 515eadf9e4e0b82703b11b1e2c63335b323aedb0 Mon Sep 17 00:00:00 2001 From: dsyddall Date: Mon, 27 Nov 2023 08:12:34 +0000 Subject: [PATCH] fix(runner): preserve fixtures when calling runif and skipif (fix #4585) (#4591) --- packages/runner/src/suite.ts | 8 ++++++-- test/core/test/fixture-initialization.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index 7dbcf9d4e026..dbec99b184b9 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -269,8 +269,12 @@ export function createTaskCollector( } } - taskFn.skipIf = (condition: any) => (condition ? test.skip : test) as TestAPI - taskFn.runIf = (condition: any) => (condition ? test : test.skip) as TestAPI + taskFn.skipIf = function (this: TestAPI, condition: any) { + return condition ? this.skip : this + } + taskFn.runIf = function (this: TestAPI, condition: any) { + return condition ? this : this.skip + } taskFn.extend = function (fixtures: Fixtures>) { const _context = mergeContextFixtures(fixtures, context) diff --git a/test/core/test/fixture-initialization.test.ts b/test/core/test/fixture-initialization.test.ts index 42f7d1098e22..9edac0631575 100644 --- a/test/core/test/fixture-initialization.test.ts +++ b/test/core/test/fixture-initialization.test.ts @@ -82,6 +82,14 @@ describe('fixture initialization', () => { }) }) + myTest.runIf(true)('fixtures work with runIf', ({ a }) => { + expect(a).toBe(1) + }) + + myTest.skipIf(false)('fixtures work with skipIf', ({ a }) => { + expect(a).toBe(1) + }) + describe('fixture dependency', () => { myTest2('b => a', ({ b }) => { expect(b).toBe('2')