Skip to content

Commit

Permalink
chore: update tests for new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkifer committed May 20, 2024
1 parent 227ff12 commit c5f5cb3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
25 changes: 11 additions & 14 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @jest-environment jsdom
*/

import skift from '../src/index';
import { SplitTest } from '../src/splitTest';

Expand All @@ -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();
});
});

Expand All @@ -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' })
Expand All @@ -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', () => {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -109,7 +107,6 @@ describe('Top-level api', () => {
const initializedPromise = test.isInitialized();

expect(await initializedPromise).toBe(false);
done();
});
});
});
8 changes: 8 additions & 0 deletions tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit c5f5cb3

Please sign in to comment.