Comments (3)
Hello guys, thanks for the issue!
For what I can see chai-spies is not able change the return value of a function. Chai's focus is actually doing assertions, so you can only run things related to assertions on spies.
To create stubs for your functions you can use SinonJS.
EDIT: I'm not sure if I totally understand your doubt, but I was reading this again and actually we have this:
/**
* # chai.spy.returns (function)
*
* Creates a spy which returns static value.
*
* var method = chai.spy.returns(true);
*
* @param {*} value static value which is returned by spy
* @returns new spy function which returns static value
* @api public
*/
I hope it is what you guys were looking for.
from chai-spies.
Hey @narainsagar @scaljeri and @lucasfcosta 😄
Right now the spy.on
API doesn't allow you to override the functionality. Some discussion has gone on about this in #38 (see #38 (comment)). The alternatives so far are:
Array.prototype.push = chai.spy(function () { return undefined });
Array.prototype.push = chai.spy.returns(undefined);
Array.prototype.push = function () { return undefined; }
chai.spy.on(Array.prototype, 'push');
We've discussed before about having extra methods on the spy interface, but we'd like to move away from that (#38 has some on this, as does this comment in #35: #35 (comment)).
I'll close this, because it's on the radar and will likely come as a result of #38. If you want to help out, continuing the discussion there would be awesome!
from chai-spies.
+1 I would really like to know this too!
from chai-spies.
Related Issues (20)
- Expect nested method to have been called
- ChaiSpies with Chai As Promiesed w/o using Timeout HOT 3
- TypeError: Cannot use 'in' operator to search for 'Date' in global HOT 1
- Bring back spy.reset() HOT 6
- export spy function as names export from chai-spies HOT 1
- An in-range update of mocha is breaking the build 🚨 HOT 16
- Restoring issue HOT 4
- Module '"chai-spies"' has no exported member 'spies'. HOT 3
- Incorrect type definitions for `spy.interface` HOT 1
- Feature: called with reports actual arguments
- `spy.on` doesn't work with nullish prototype
- expect(...).to.have.been.called.once is not a function HOT 2
- chai-spies.js needs a rebuild on master HOT 9
- to.have.been.called.with() throws an error HOT 3
- Switch logicalparadox refs to chaijs HOT 4
- expect(spy).to.have.been.called.with always true HOT 6
- An in-range update of mocha is breaking the build 🚨 HOT 3
- An in-range update of rollup-plugin-commonjs is breaking the build 🚨 HOT 4
- Cannot attach spy on the same function more than once HOT 2
- spy.interface documentation appears to be wrong HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-spies.