1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test
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
..
data Use chainId values for the address book (#9565) 2020-10-12 16:35:55 -07:00
e2e Robustify waiting logic in e2e test (#9704) 2020-10-23 16:24:20 -07:00
lib Add prettier-plugin-sort-json (#9450) 2020-09-23 12:21:42 -02:30
stub Fix fetching of swap quotes when initial network was testnet (#9726) 2020-10-27 13:22:21 -02:30
unit Replace shared mocks in incoming transaction controller tests (#9754) 2020-10-29 12:46:04 -02:30
unit-global Fix no-empty-function issues (#9216) 2020-08-14 09:17:02 -02:30
env.js Remove cross-env (#7950) 2020-01-30 14:11:26 -03:30
helper.js Update @metamask/eslint-config to v4.1.0 (#9663) 2020-10-21 14:01:03 -02:30
setup.js Remove obs-store babel register handling (#8413) 2020-04-27 07:54:42 -07:00