{
super(props);
}
- render() {
+ render(): JSX.Element {
return (
{JSON.stringify({ ...this.props })}
@@ -51,11 +52,13 @@ describe('withOptimizely', () => {
beforeEach(() => {
optimizelyClient = ({
setUser: jest.fn(),
+ getVuid: jest.fn(),
+ onReady: jest.fn(),
} as unknown) as ReactSDKClient;
});
describe('when userId / userAttributes props are provided', () => {
- it('should call setUser with the correct user id / attributes', () => {
+ it('should call setUser with the correct user id / attributes', async () => {
const attributes = {
foo: 'bar',
};
@@ -66,13 +69,13 @@ describe('withOptimizely', () => {
);
- expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1));
expect(optimizelyClient.setUser).toHaveBeenCalledWith({ id: userId, attributes });
});
});
describe('when only userId prop is provided', () => {
- it('should call setUser with the correct user id / attributes', () => {
+ it('should call setUser with the correct user id / attributes', async () => {
const userId = 'jordan';
render(
@@ -80,7 +83,7 @@ describe('withOptimizely', () => {
);
- expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1));
expect(optimizelyClient.setUser).toHaveBeenCalledWith({
id: userId,
attributes: {},
@@ -89,7 +92,7 @@ describe('withOptimizely', () => {
});
describe(`when the user prop is passed only with "id"`, () => {
- it('should call setUser with the correct user id / attributes', () => {
+ it('should call setUser with the correct user id / attributes', async () => {
const userId = 'jordan';
render(
@@ -97,7 +100,7 @@ describe('withOptimizely', () => {
);
- expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1));
expect(optimizelyClient.setUser).toHaveBeenCalledWith({
id: userId,
attributes: {},
@@ -106,7 +109,7 @@ describe('withOptimizely', () => {
});
describe(`when the user prop is passed with "id" and "attributes"`, () => {
- it('should call setUser with the correct user id / attributes', () => {
+ it('should call setUser with the correct user id / attributes', async () => {
const userId = 'jordan';
const attributes = { foo: 'bar' };
render(
@@ -115,7 +118,7 @@ describe('withOptimizely', () => {
);
- expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1));
expect(optimizelyClient.setUser).toHaveBeenCalledWith({
id: userId,
attributes,
@@ -124,7 +127,7 @@ describe('withOptimizely', () => {
});
describe('when both the user prop and userId / userAttributes props are passed', () => {
- it('should respect the user object prop', () => {
+ it('should respect the user object prop', async () => {
const userId = 'jordan';
const attributes = { foo: 'bar' };
render(
@@ -139,7 +142,7 @@ describe('withOptimizely', () => {
);
- expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(optimizelyClient.setUser).toHaveBeenCalledTimes(1));
expect(optimizelyClient.setUser).toHaveBeenCalledWith({
id: userId,
attributes,
@@ -160,7 +163,7 @@ describe('withOptimizely', () => {
)
);
- expect(optimizelyClient.setUser).not.toHaveBeenCalled();
+ expect(optimizelyClient.setUser).toHaveBeenCalled();
});
it('should inject the isServerSide prop', async () => {
@@ -187,13 +190,9 @@ describe('withOptimizely', () => {
const OptimizelyInput = withOptimizely(ForwardingFancyInput);
const inputRef: React.RefObject = React.createRef();
- const optimizelyMock: ReactSDKClient = ({
- setUser: jest.fn(),
- } as unknown) as ReactSDKClient;
-
render(
{
);
+ expect(inputRef).toBeDefined();
expect(inputRef.current).toBeInstanceOf(HTMLInputElement);
- expect(typeof inputRef.current!.focus).toBe('function');
+ expect(typeof inputRef.current?.focus).toBe('function');
const inputNode: HTMLInputElement = screen.getByTestId('input-element');
- expect(inputRef.current!).toBe(inputNode);
+ expect(inputRef.current).toBe(inputNode);
});
it('should hoist non-React statics', () => {