Skip to content

Commit 54aaea6

Browse files
Unit tests
1 parent 284d1ee commit 54aaea6

File tree

9 files changed

+93
-37
lines changed

9 files changed

+93
-37
lines changed

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: echo "VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
5050

5151
- name: SonarQube Scan (Push)
52-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/fallback-treatment-support')
52+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development')
5353
uses: SonarSource/sonarcloud-github-action@v1.9
5454
env:
5555
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
@@ -77,7 +77,7 @@ jobs:
7777
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
7878
7979
- name: Store assets
80-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/fallback-treatment-support')
80+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development')
8181
uses: actions/upload-artifact@v4
8282
with:
8383
name: assets
@@ -88,7 +88,7 @@ jobs:
8888
name: Upload assets
8989
runs-on: ubuntu-latest
9090
needs: build
91-
if: github.event_name == 'push' && github.ref == 'refs/heads/fallback-treatment-support'
91+
if: github.event_name == 'push' && github.ref == 'refs/heads/development'
9292
strategy:
9393
matrix:
9494
environment:

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2.6.0 (October 31, 2025)
1+
2.6.0 (November 4, 2025)
22
- Added `useTreatment`, `useTreatments`, `useTreatmentWithConfig` and `useTreatmentsWithConfig` hooks to replace the now deprecated `useSplitTreatments` hook.
33
- Updated @splitsoftware/splitio package to version 11.8.0 that includes minor updates:
44
- Added new configuration for Fallback Treatments, which allows setting a treatment value and optional config to be returned in place of "control", either globally or by flag. Read more in our docs.

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-react",
3-
"version": "2.5.1-rc.0",
3+
"version": "2.6.0",
44
"description": "A React library to easily integrate and use Split JS SDK",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",
@@ -63,7 +63,7 @@
6363
},
6464
"homepage": "https://github.com/splitio/react-client#readme",
6565
"dependencies": {
66-
"@splitsoftware/splitio": "11.7.2-rc.5",
66+
"@splitsoftware/splitio": "11.8.0",
6767
"memoize-one": "^5.1.1",
6868
"shallowequal": "^1.1.0",
6969
"tslib": "^2.3.1"

src/__tests__/testUtils/sdkConfigs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ export const sdkBrowser: SplitIO.IBrowserSettings = {
44
key: 'customer-key',
55
},
66
};
7+
8+
export const sdkBrowserWithConfig: SplitIO.IBrowserSettings = {
9+
...sdkBrowser,
10+
fallbackTreatments: {
11+
global: 'control_global',
12+
byFlag: { ff1: { treatment: 'control_ff1', config: 'control_ff1_config' } }
13+
}
14+
};

src/__tests__/useTreatment.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('@splitsoftware/splitio/client', () => {
77
return { SplitFactory: mockSdk() };
88
});
99
import { SplitFactory } from '@splitsoftware/splitio/client';
10-
import { sdkBrowser } from './testUtils/sdkConfigs';
10+
import { sdkBrowser, sdkBrowserWithConfig } from './testUtils/sdkConfigs';
1111
import { CONTROL, EXCEPTION_NO_SFP } from '../constants';
1212

1313
/** Test target */
@@ -96,7 +96,7 @@ describe('useTreatment', () => {
9696
}).toThrow(EXCEPTION_NO_SFP);
9797
});
9898

99-
test('useTreatment must update on SDK events', async () => {
99+
test('must update on SDK events', async () => {
100100
const outerFactory = SplitFactory(sdkBrowser);
101101
const mainClient = outerFactory.client() as any;
102102
const user2Client = outerFactory.client('user_2') as any;
@@ -171,4 +171,16 @@ describe('useTreatment', () => {
171171
expect(user2Client.getTreatment).toHaveBeenLastCalledWith('split_test', undefined, undefined);
172172
});
173173

174+
test('returns fallback treatment if the client is not operational', () => {
175+
render(
176+
<SplitFactoryProvider config={sdkBrowserWithConfig} >
177+
{React.createElement(() => {
178+
expect(useTreatment({ name: featureFlagName, attributes, properties }).treatment).toEqual('control_global');
179+
expect(useTreatment({ name: 'ff1', attributes, properties }).treatment).toEqual('control_ff1');
180+
return null;
181+
})}
182+
</SplitFactoryProvider>
183+
);
184+
});
185+
174186
});

src/__tests__/useTreatmentWithConfig.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('@splitsoftware/splitio/client', () => {
77
return { SplitFactory: mockSdk() };
88
});
99
import { SplitFactory } from '@splitsoftware/splitio/client';
10-
import { sdkBrowser } from './testUtils/sdkConfigs';
10+
import { sdkBrowser, sdkBrowserWithConfig } from './testUtils/sdkConfigs';
1111
import { CONTROL_WITH_CONFIG, EXCEPTION_NO_SFP } from '../constants';
1212

1313
/** Test target */
@@ -96,7 +96,7 @@ describe('useTreatmentWithConfig', () => {
9696
}).toThrow(EXCEPTION_NO_SFP);
9797
});
9898

99-
test('useTreatmentWithConfig must update on SDK events', async () => {
99+
test('must update on SDK events', async () => {
100100
const outerFactory = SplitFactory(sdkBrowser);
101101
const mainClient = outerFactory.client() as any;
102102
const user2Client = outerFactory.client('user_2') as any;
@@ -171,4 +171,16 @@ describe('useTreatmentWithConfig', () => {
171171
expect(user2Client.getTreatmentWithConfig).toHaveBeenLastCalledWith('split_test', undefined, undefined);
172172
});
173173

174+
test('returns fallback treatment if the client is not operational', () => {
175+
render(
176+
<SplitFactoryProvider config={sdkBrowserWithConfig} >
177+
{React.createElement(() => {
178+
expect(useTreatmentWithConfig({ name: featureFlagName, attributes, properties }).treatment).toEqual({ treatment: 'control_global', config: null });
179+
expect(useTreatmentWithConfig({ name: 'ff1', attributes, properties }).treatment).toEqual({ treatment: 'control_ff1', config: 'control_ff1_config' });
180+
return null;
181+
})}
182+
</SplitFactoryProvider>
183+
);
184+
});
185+
174186
});

src/__tests__/useTreatments.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('@splitsoftware/splitio/client', () => {
77
return { SplitFactory: mockSdk() };
88
});
99
import { SplitFactory } from '@splitsoftware/splitio/client';
10-
import { sdkBrowser } from './testUtils/sdkConfigs';
10+
import { sdkBrowser, sdkBrowserWithConfig } from './testUtils/sdkConfigs';
1111
import { CONTROL, EXCEPTION_NO_SFP } from '../constants';
1212

1313
/** Test target */
@@ -132,7 +132,7 @@ describe('useTreatments', () => {
132132
);
133133
});
134134

135-
test('useTreatments must update on SDK events', async () => {
135+
test('must update on SDK events', async () => {
136136
const outerFactory = SplitFactory(sdkBrowser);
137137
const mainClient = outerFactory.client() as any;
138138
const user2Client = outerFactory.client('user_2') as any;
@@ -226,4 +226,16 @@ describe('useTreatments', () => {
226226
);
227227
});
228228

229+
test('returns fallback treatments if the client is not operational', () => {
230+
render(
231+
<SplitFactoryProvider config={sdkBrowserWithConfig} >
232+
{React.createElement(() => {
233+
const { treatments } = useTreatments({ names: ['ff1', 'ff2'], attributes, properties });
234+
expect(treatments).toEqual({ ff1: 'control_ff1', ff2: 'control_global' });
235+
return null;
236+
})}
237+
</SplitFactoryProvider>
238+
);
239+
});
240+
229241
});

src/__tests__/useTreatmentsWithConfig.test.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('@splitsoftware/splitio/client', () => {
77
return { SplitFactory: mockSdk() };
88
});
99
import { SplitFactory } from '@splitsoftware/splitio/client';
10-
import { sdkBrowser } from './testUtils/sdkConfigs';
10+
import { sdkBrowser, sdkBrowserWithConfig } from './testUtils/sdkConfigs';
1111
import { CONTROL_WITH_CONFIG, EXCEPTION_NO_SFP } from '../constants';
1212

1313
/** Test target */
@@ -132,7 +132,7 @@ describe('useTreatmentsWithConfig', () => {
132132
);
133133
});
134134

135-
test('useTreatmentsWithConfig must update on SDK events', async () => {
135+
test('must update on SDK events', async () => {
136136
const outerFactory = SplitFactory(sdkBrowser);
137137
const mainClient = outerFactory.client() as any;
138138
const user2Client = outerFactory.client('user_2') as any;
@@ -232,4 +232,16 @@ describe('useTreatmentsWithConfig', () => {
232232
);
233233
});
234234

235+
test('returns fallback treatments if the client is not operational', () => {
236+
render(
237+
<SplitFactoryProvider config={sdkBrowserWithConfig} >
238+
{React.createElement(() => {
239+
const { treatments } = useTreatmentsWithConfig({ names: ['ff1', 'ff2'], attributes, properties });
240+
expect(treatments).toEqual({ ff1: { treatment: 'control_ff1', config: 'control_ff1_config' }, ff2: { treatment: 'control_global', config: null } });
241+
return null;
242+
})}
243+
</SplitFactoryProvider>
244+
);
245+
});
246+
235247
});

0 commit comments

Comments
 (0)