Skip to content

Test independance violation #22

@Klemo1997

Description

@Klemo1997

I just found a dependency between tests in tag cucumber in files:

  • MenuButtons.test.js
  • sharingSagas.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions