1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/test/unit/app/controllers
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
..
network Merge pull request from GHSA-c2xw-px2x-pr65 2020-10-06 15:27:02 -02:30
permissions Update ESLint shared config to v3 (#9274) 2020-08-19 13:57:05 -02:30
transactions Refactor background Segment usage (#9509) 2020-10-08 09:41:23 -07:00
cached-balances-test.js Fix no-empty-function issues (#9216) 2020-08-14 09:17:02 -02:30
detect-tokens-test.js Use Infura v3 API (#9368) 2020-09-10 13:46:00 -02:30
ens-controller-test.js Fix import/no-extraneous-dependencies issues (#9232) 2020-08-14 17:34:56 -02:30
incoming-transactions-test.js Replace shared mocks in incoming transaction controller tests (#9754) 2020-10-29 12:46:04 -02:30
metamask-controller-test.js Remove localhost provider type (#9551) 2020-10-12 12:05:40 -07:00
preferences-controller-test.js Remove localhost provider type (#9551) 2020-10-12 12:05:40 -07:00
swaps-test.js Fix swaps when initial network not Mainnet (#9745) 2020-10-28 16:17:32 -02:30
token-rates-controller.js Fix import/order issues (#9239) 2020-08-18 16:48:25 -02:30