Test-driving a WebSocket connection
We start by filling out that first function, startSharing
. This function is invoked when the START_SHARING
action is received. That action is triggered when the user clicks the Start sharing button:
- Open
test/middleware/sharingSagas.test.js
and add the following imports at the top:import { storeSpy, expectRedux } from "expect-redux"; import { act } from "react-dom/test-utils"; import { configureStore } from "../../src/store";
- At the bottom of the file, add a new
describe
block and its setup. We’ll break this into a couple of steps: first, set up the Redux store and the WebSocket spy. Becausewindow.WebSocket
is a constructor function, we usemockImplementation
to stub it out:describe("sharingSaga", () => { let store; let socketSpyFactory; beforeEach(() => { store = configureStore([storeSpy]); socketSpyFactory...