Skip to content

Commit

Permalink
update react unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar committed Aug 2, 2024
1 parent 462cba8 commit 520d9d7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/headless-react/src/ssr/search-engine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {defineSearchEngine} from './search-engine.js';

describe('Headless react SSR utils', () => {
let errorSpy: jest.SpyInstance;
const mockedNavigatorContextProvider = jest.fn();
const sampleConfig = {
...getSampleSearchEngineConfiguration(),
analytics: {enabled: false}, // TODO: KIT-2585 Remove after analytics SSR support is added
Expand All @@ -34,6 +35,7 @@ describe('Headless react SSR utils', () => {
controllers,
StaticStateProvider,
HydratedStateProvider,
setNavigatorContextProvider,
...rest
} = defineSearchEngine({
configuration: sampleConfig,
Expand All @@ -46,6 +48,7 @@ describe('Headless react SSR utils', () => {
useEngine,
StaticStateProvider,
HydratedStateProvider,
setNavigatorContextProvider,
].forEach((returnValue) => expect(typeof returnValue).toBe('function'));

expect(controllers).toEqual({});
Expand Down Expand Up @@ -81,6 +84,7 @@ describe('Headless react SSR utils', () => {
StaticStateProvider,
HydratedStateProvider,
controllers,
setNavigatorContextProvider,
useEngine,
} = engineDefinition;

Expand Down Expand Up @@ -131,6 +135,7 @@ describe('Headless react SSR utils', () => {
});

test('should render with StaticStateProvider', async () => {
setNavigatorContextProvider(mockedNavigatorContextProvider);
const staticState = await fetchStaticState();
render(
<StaticStateProvider controllers={staticState.controllers}>
Expand All @@ -142,6 +147,7 @@ describe('Headless react SSR utils', () => {
});

test('should hydrate results with HydratedStateProvider', async () => {
setNavigatorContextProvider(mockedNavigatorContextProvider);
const staticState = await fetchStaticState();
const {engine, controllers} = await hydrateStaticState(staticState);

Expand All @@ -159,6 +165,7 @@ describe('Headless react SSR utils', () => {
let hydratedState: InferHydratedState<typeof engineDefinition>;

beforeEach(async () => {
setNavigatorContextProvider(mockedNavigatorContextProvider);
staticState = await fetchStaticState();
hydratedState = await hydrateStaticState(staticState);
});
Expand Down

0 comments on commit 520d9d7

Please sign in to comment.