Comments (7)
Hey Guys!
- Regarding the usage of methods or getters, I think it's a matter of preference. If we take a look at Sinon.JS, we'll see that most of its API are methods. One benefit of using methods is that they're scalable to changes without introducing a breaking change. For example, they can take additional parameters.
- IMHO the API should be simple and thin. Most of the usage will be to check the current value that was emitted.
from observer-spy.
Hey everyone!
+1 for flat in favor of nested.
Concerning properties vs methods, I like how properties are shorter... but even if we ignore extensibility by adding parameters, the problem we get is the inconsistency between using props for values
and methods for things like getValueAt()
.
I think that the most important thing here is consistency. For instance, hasReceivedNext() & getValues()
vs receivedNext() & values()
.
I generally prefer the latest as it's shorted but we have to make sure that we'll never use any properties to be the least surprising.
from observer-spy.
Well, that's a very interesting suggestion!
I like that the new API approach clearly hints that spy instances are stateful. That might benefit the readability of test specs where you want to go beyond checking basic behavior.
Maybe it would be helpful here to consider where this library will be heading to. What's your vision @shairez ? 🤩
If ObserverSpies should someday evolve to a comprehensive scheduler-free alternative to marble-testing, I would move forward with the new API suggestions.
Right now, I use ObserverSpies more like a supplement to marble-testing and like the simplicity of its API. That's why I rather prefer the current way of exposing only methods with prefixes (is/has/on/get). Each method has its decisive intention, and it feels somehow more consistent.
But that's just my opinion. I'm curious to see what's next. And if there is anything I can help with, let me know!
from observer-spy.
Appreciate the feedback @yjaaidi !
I agree with your points and also that shorter is better, though getValues()
feels better to me than values()
(maybe it's a matter of being used to it or something)
from observer-spy.
Thanks @katharinakoal for your feedback!
My aim for this library is to keep it small and simple.
That's why I like a more flattened API (vs nested).
And that's where Thomas wanted to take this library too - towards an API he believes is better and simpler than the current one.
I actually didn't plan to replace marble testing, just to make 90% of the every day app use cases easier to test :)
The question in this issue I believe comes down to - which is better - .getValues()
or .values
(and the rest of them)
I'm trying to find reasons other than "I like this style better because I'm used to it", but to actually show how it is saving time while reducing confusion.
So maybe something like "In the following test, look how this api is much cleaner and clearer" (followed by a code example)
I know my experience is just one man's experience, so I try to incorporate as many perspectives as I can to make sure we have an API that covers as much use cases while keeping it elegant and small.
from observer-spy.
Good points @NetanelBasal !
Thanks for sharing your feedback 🙏
from observer-spy.
Finally I had some time to get back to these issues 😅
I'm closing this issue as it seems like the majority thinks it's better to stay with methods.
Thanks everyone for participating!
BTW, You can view the latest release with @ThomasBurleson 's improvements here -
https://github.com/hirezio/observer-spy/releases/tag/v1.4.0
from observer-spy.
Related Issues (16)
- Promise support for `onComplete` HOT 4
- DISCUSSION 2: ObserverSpy API - passing `OnComplete` callback in the constructor? HOT 8
- DISCUSSION 3: `subscribeAndSpyOn` + `unsubscribe` VS `spyOn` and `dispose` HOT 10
- `ObserverSpy` swallows errors HOT 1
- is there a method to count the number of times the source observable has emitted? HOT 5
- The automated release is failing 🚨
- Jest matchers HOT 8
- Requires ESM module transformation HOT 7
- Support for RxJS 7 HOT 1
- subscribeSpyTo is causing the ''ERROR TypeError: You provided 'undefined' where a stream was expected'' with the RxJS 7 upgrade HOT 2
- subscribeSpyTo<T> returns SubscriberSpy<unknown> instead of SubscriberSpy<T> HOT 6
- Make .expectErrors() return this HOT 5
- Await .onFirstEmitted() and .onEmitted(n); of observable values and then continue HOT 5
- Improve .receivedNext()
- Simplify usage with factory function and internal subscription handling HOT 7
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 observer-spy.