balderdashy / balderdashy/sails
Stub SailsJs helper function which is called with named arguments
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Node version**: 10.X
**Sails version** _(sails)_: 1.2.3
I'm trying to mock/stub a sailsjs helper function which is called with named arguments. Using `sinon` library for function mocking.
Example:
function call that needs to be mocked: `await sails.helpers.getData.with({})`
Tried Solutions:
1) `sinon.stub(sails.helpers, 'getData').returns(true)`
issue -> sails.helpers.getData.with is not a function
2) `sinon.stub(sails.helpers.getData, 'with').returns(true)`
issue -> Cannot redefine property: with
reason -> non-configurable property is set to false for sails object. And we can't change that.
3) Tried creating a fake function and adding it to `sails.helpers.getData['with']` property
4) Also tried setting special setters to `sails.helpers.getData` object with the help of rewire library.
What is the way to stub a helper which is called with named args.
Contributor guide
Research direction
Start from the reported call `sails.helpers.getData.with({})` and reproduce it with Node 10.x, Sails 1.2.3, Sinon, and the three stubbing approaches described. Trace how the named-argument helper is exposed and determine what a supported test double must preserve; done means a reproducible stubbing method or a clearly documented limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100