From c5f5cb3c3d6111d786e13a14285df21629ff8cd4 Mon Sep 17 00:00:00 2001 From: kamilkifer <47425451+kamilkifer@users.noreply.github.com> Date: Mon, 20 May 2024 11:42:18 +0100 Subject: [PATCH] chore: update tests for new versions --- tests/api.spec.ts | 25 +++++++++++-------------- tests/config.spec.ts | 8 ++++++++ tests/query.spec.ts | 3 +++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/api.spec.ts b/tests/api.spec.ts index 442df61..0ff8259 100644 --- a/tests/api.spec.ts +++ b/tests/api.spec.ts @@ -1,3 +1,7 @@ +/** + * @jest-environment jsdom + */ + import skift from '../src/index'; import { SplitTest } from '../src/splitTest'; @@ -7,13 +11,12 @@ describe('Top-level api', () => { expect(skift).toBeDefined(); }); - it('should be impossible to create an empty test', (done) => { + it('should be impossible to create an empty test', () => { skift.create('Awesome test!').setup() .then(() => expect('not').toBe('here')) .catch((err) => { expect(skift.getTest('Awesome test!')).toBeDefined(); expect(skift.getTest('Awesome test!') instanceof SplitTest).toBe(true); - done(); }); }); @@ -25,7 +28,7 @@ describe('Top-level api', () => { expect(test.getVariation('Variation A')).toBeDefined(); }); - it('should be possible to setup a test with two variations and retrieve it by name', async (done) => { + it('should be possible to setup a test with two variations and retrieve it by name', async () => { const test = skift .create('Another awesome test!') .addVariation({ name: 'Variation C' }) @@ -34,7 +37,6 @@ describe('Top-level api', () => { expect(await test.setup()).toBe(true); expect(skift.getTest('Another awesome test!')).toBeDefined(); expect(test === skift.getTest('Another awesome test!')).toBeTruthy(); - done(); }); it('should be possible to show the UI', () => { @@ -52,27 +54,25 @@ describe('Top-level api', () => { }); describe('when setting a condition', () => { - it('allows for a promise', async (done) => { + it('allows for a promise', async () => { expect(await skift .create('testing conditions') .setCondition(() => Promise.resolve(true)) .addVariation({ name: 'A'}) .setup()).toBe(true); - done(); }); - it('allows for a boolean', async (done) => { + it('allows for a boolean', async () => { expect(await skift .create('testing conditions') .setCondition(() => true) .addVariation({ name: 'A'}) .setup()).toBe(true); - done(); }); }); describe('when checking for initialization', () => { - it('resolves to true when setup is called, completes, and was successful', async (done) => { + it('resolves to true when setup is called, completes, and was successful', async () => { const test = skift .create('testing conditions') .setCondition(() => true) @@ -83,10 +83,9 @@ describe('Top-level api', () => { await setupPromise; expect(await initializedPromise).toBe(true); - done(); }); - it('resolves to false when setup is called, completes, and was canceled', async (done) => { + it('resolves to false when setup is called, completes, and was canceled', async () => { const test = skift .create('testing conditions') .setCondition(() => false) @@ -97,10 +96,9 @@ describe('Top-level api', () => { await setupPromise; expect(await initializedPromise).toBe(false); - done(); }); - it('resolves to false when setup is never called', async (done) => { + it('resolves to false when setup is never called', async () => { const test = skift .create('testing conditions') .setCondition(() => false) @@ -109,7 +107,6 @@ describe('Top-level api', () => { const initializedPromise = test.isInitialized(); expect(await initializedPromise).toBe(false); - done(); }); }); }); diff --git a/tests/config.spec.ts b/tests/config.spec.ts index 5ec3392..c647c83 100644 --- a/tests/config.spec.ts +++ b/tests/config.spec.ts @@ -1,6 +1,14 @@ +/** + * @jest-environment jsdom + */ + import config from '../src/config'; import skift from '../src/index'; +/** + * @jest-environment jsdom + */ + describe('Config', () => { it('should get default configuration', () => { expect(config).toBeDefined(); diff --git a/tests/query.spec.ts b/tests/query.spec.ts index 8daeba1..b4fae1b 100644 --- a/tests/query.spec.ts +++ b/tests/query.spec.ts @@ -25,6 +25,9 @@ describe('Query', () => { describe('#getAbTestParameter', () => { it('should return null if there is no query', () => { + const location = { + search: '', + }; const abtest = query.getAbTestParameter(location.search); expect(abtest).toBeNull(); });