1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/test/unit
Mark Stacey d99d8591f0
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.

We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.

In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.

The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.

Instead we should never share mocks in the first place, which has other
benefits anyway.

This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 12:46:04 -02:30
..
actions Update @metamask/eslint-config to v4.1.0 (#9663) 2020-10-21 14:01:03 -02:30
app Replace shared mocks in incoming transaction controller tests (#9754) 2020-10-29 12:46:04 -02:30
lib Fix import/order issues (#9239) 2020-08-18 16:48:25 -02:30
migrations Migrate 'localhost' tokens (#9570) 2020-10-13 07:07:00 -07:00
responsive/components Remove mountWithStore enzyme component wrapper (#9309) 2020-08-26 15:55:24 -07:00
ui Use chainId values for the address book (#9565) 2020-10-12 16:35:55 -07:00
balance-formatter-test.js Migrate codebase to use ESM (#7730) 2020-01-09 00:04:58 -03:30
localhostState.js Remove localhost provider type (#9551) 2020-10-12 12:05:40 -07:00