|
@@ -5,6 +5,10 @@ import * as storageHooks from 'react-storage-hooks';
|
|
|
|
|
|
|
|
import { useSocket } from './socket';
|
|
import { useSocket } from './socket';
|
|
|
|
|
|
|
|
|
|
+jest.mock('nanoid', () => ({
|
|
|
|
|
+ nanoid: (): string => 'A5v3D',
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
describe(useSocket.name, () => {
|
|
describe(useSocket.name, () => {
|
|
|
afterEach(WS.clean);
|
|
afterEach(WS.clean);
|
|
|
|
|
|
|
@@ -56,12 +60,12 @@ describe(useSocket.name, () => {
|
|
|
return renderResult;
|
|
return renderResult;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- it('should create a new connection to the socket, using the client name in the query', async () => {
|
|
|
|
|
|
|
+ it('should create a new connection to the socket, using a unique client name in the query', async () => {
|
|
|
expect.assertions(1);
|
|
expect.assertions(1);
|
|
|
setupIdentify();
|
|
setupIdentify();
|
|
|
|
|
|
|
|
const res = await server.connected;
|
|
const res = await server.connected;
|
|
|
- expect(res.url).toBe('ws://my-api.url:1234/pubsub?client-name=my-client-name');
|
|
|
|
|
|
|
+ expect(res.url).toBe('ws://my-api.url:1234/pubsub?client-name=my-client-name-A5v3D');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should open a new socket', async () => {
|
|
it('should open a new socket', async () => {
|
|
@@ -128,13 +132,13 @@ describe(useSocket.name, () => {
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should open a socket immediately, using the stored name', async () => {
|
|
|
|
|
|
|
+ it('should open a socket immediately, using a unique version of the stored name', async () => {
|
|
|
expect.assertions(3);
|
|
expect.assertions(3);
|
|
|
const { getByText } = render(<TestComponent />);
|
|
const { getByText } = render(<TestComponent />);
|
|
|
|
|
|
|
|
const res = await server.connected;
|
|
const res = await server.connected;
|
|
|
|
|
|
|
|
- expect(res.url).toBe('ws://my-api.url:1234/pubsub?client-name=my-stored-name');
|
|
|
|
|
|
|
+ expect(res.url).toBe('ws://my-api.url:1234/pubsub?client-name=my-stored-name-A5v3D');
|
|
|
|
|
|
|
|
act(() => {
|
|
act(() => {
|
|
|
fireEvent.click(getByText('Say hello!'));
|
|
fireEvent.click(getByText('Say hello!'));
|