[go: up one dir, main page]

Skip to content

Refactor diffs store tests

Right now we're testing MR diffs store as a whitebox: i.e. we know exactly what happens in every single action\mutation\getter. This is followed by mocking everything in the store: actions don't actually call other actions\mutations. The same applies to every single bit of logic tests in these tests.

This kind of isolation leads to our tests being:

  1. Fragile
  2. False positive (missing actual bugs in the code because the real code is mocked)
  3. False negative (when adding new functionality)

That means if you'd like to change, remove or add a new feature to the diffs you would have to sometimes seriously rewrite the tests, even if the logic didn't change at all. Also, the tests won't help you if you the logic itself is broken: when you mock a specific action return value you can not guarantee that the action can actually produce it.

To solve that we should refactor all the diffs store test to test diffs module as a whole package: all the state, mutations, actions and getters should never be mocked. Instead, we should only mock store dependencies: axios, scrolling functions, etc. This will make the tests much more robust and easier to work with. It will also help us ensure the tests don't break when the logic didn't change.

Edited by Stanislav Lashmanov