New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make spy/stub use consistent #1417
Comments
I prefer to have stubs initialization in Then every following Then in
Advantages: Example:
|
After a STM with @nazarhussain @willclarktech @4miners we conculded that we are not going to fix this issue and move the issue to backlog. For the short term any PR which has test using stub and spies need to complie with the following standard discussed in the meeting. In each of the unit test, the test setup will have Here is an example from TestFile.js
_global_hooks.js
@diego-G as discussed you can remove the milestone for this issue and keep it in backlog, once modularization is implemented and the tests are fixed as described by @willclarktech we can close the issue. |
As we are migrating from mocha to jest, and also we recreated the application structure, we are already on the direction of making tests atomic. So it is ok to close this issue. |
Expected behavior
We should follow a consistent pattern for stub use. We should make use of the sinon sandbox for ease of restoration. One option is to have a global
afterEach
hook which callssinonSandbox.restore()
, but this would require refactoring tests which make multipleit
block assertions with a sharedbefore
hook spy/stub setup.Actual behavior
We use a variety of patterns, not all of which make sense even besides the consistency issue. Some examples of the various patterns being used follow.
Creating spies/stubs in a
describe
block, e.g.:https://github.com/LiskHQ/lisk/blob/699104486288d6380704ea3d22f30470480e96fa/test/unit/modules/rounds.js#L34-L42
Creating spies/stubs in a
before
hook and restoring in anafter
hook, e.g.:https://github.com/LiskHQ/lisk/blob/699104486288d6380704ea3d22f30470480e96fa/test/unit/modules/rounds.js#L121-L134
Restoring/resetting in a
beforeEach
hook, e.g.:https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/api/ws/workers/peersUpdateRules.js#L312-L333
Creating spies/stubs in a
beforeEach
hook, e.g.:https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/logic/delegate.js#L95-L114
Assigning to a variable and calling sinon methods via that variable, e.g.:
https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/helpers/git.js#L26-L30
Stubbing without assignment and calling sinon methods directly on the stubbed method, e.g.:
https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/api/ws/workers/peersUpdateRules.js#L43
Reassigning a stubbed method to itself (redundant assignment), e.g.:
https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/api/ws/workers/peersUpdateRules.js#L147
Apparently unused spies/stubs/mocks, e.g.:
https://github.com/LiskHQ/lisk/blob/8e6eb462a2181ffd327fe7b58757727e47177d87/test/unit/logic/delegate.js#L91-L93
Which version(s) does this affect? (Environment, OS, etc...)
1.0.0
The text was updated successfully, but these errors were encountered: