We'll repeat a lot of the same techniques in this section. There are two new concepts: first, pulling out the search param for the watcher ID, and second, using eventChannel to subscribe to the WebSocket onmessage callback:
- Write a new describe block at the bottom of test/middleware/sharingSagas.test.js, but still nested inside the main describe block:
describe('watching', () => {
beforeEach(() => {
Object.defineProperty(window, 'location', {
writable: true,
value: {
host: 'test:1234',
pathname: '/index.html',
search: '?watching=234'
}
});
});
it('opens a socket when the page loads', () => {
store.dispatch({ type: 'TRY_START_WATCHING' });
expect(socketSpyFactory).toHaveBeenCalledWith(
'ws://test:1234...