-
Notifications
You must be signed in to change notification settings - Fork 558
Description
I just found a dependency between tests in tag cucumber in files:
MenuButtons.test.jssharingSagas.test.js
There is a missing reset of socketSpy variable, which should be set to default state after each test or else it can possibly change the behavior of tests.
Fix is as simple as adding one line into both files:
// MenuButtons.test.js
describe('MenuButtons', () => {
...
describe('sharing button', () => {
...
afterEach(() => {
...
// Add this line
socketSpy = undefined;
});
...
});
...
});// sharingSagas.test.js
describe('sharingSaga', () => {
...
afterEach(() => {
...
// Add this line
socketSpy = undefined;
});
...
});This unfornately causes the breakage of test dispatches an action of STOP_SHARING when stop sharing is clicked in MenuButtons.test.js due to failure of function notifySocketOpened where the socketSpy is undefined and it is trying to reach its onopen callback property.
Testcase works because socketSpy is set previously in test dispatches an action of START_SHARING when start sharing is clicked and just skipping this test causes test case failure as well.
Solution would be to somehow call startSharing saga that creates WebSocket and therefore sets the onopen callback property . Easiest solution appears to be just adding this line to test:
// sharingSagas.js
...
it('dispatches an action of STOP_SHARING when stop sharing is clicked', async () => {
const store = renderWithStore(<MenuButtons />);
// Add this line
click(button('Start sharing'));
store.dispatch({ type: 'STARTED_SHARING' });
await notifySocketOpened();
click(button('Stop sharing'));
return expectRedux(store)
.toDispatchAnAction()
.matching({ type: 'STOP_SHARING' });
});Hope it helps.