Comments (8)
Thanks @katharinakoal @NetanelBasal @yjaaidi for your feedback!
Younes - yeah, I agree with returning a promise
That's what was solved by @edbzn 's PR #3
The original observerSpy.onComplete()
callback was added because I just didn't think about async-await.
And that's why I love open-source so much 😄
One use case I can think of is maybe older code that doesn't support async-await or promises, but I don't think it's that common, so we might just remove it in the future...
from observer-spy.
I'm not sure what's the use case for this hook. In addition to that, if you add the onComplete
hook, it makes sense to be consistent and expose onError
and onNext
hooks.
from observer-spy.
Solution: I wouldn't implement this feature. 😁
Alternative: I would replace by it by .whenComplete(): Promise
and only document usage for await observer.whenComplete()
.
Reason: I think that tests should never use callbacks because:
- they makes tests harder to read
- most users might forget to call
done()
- allowing callbacks encourages waterfall
- it kind of breaks one of the purposes of
ObserverSpy
which is to avoid assertions in the subscribe
If we keep it, I would expect it to be an Observable
so I can use it this way observer.onComplete.subscribe(completeObserverSpy)
😜
I might miss some edge case where a callback is easier to read... but I can't figure it out.
from observer-spy.
I want to add a point to the downsides:
When overloading the constructor, it might be confusing to "guess" how the argument influences the instance.
This could be solved by adding a static factory method like this:
const spy = ObserverSpy.withCompleteCallback(fn)
But then again, it's getting a bit complex. Maybe it's worth it, and I'm just missing some other advantages?
from observer-spy.
Hi, agree with @yjaaidi about using Promises, it's always better! Maybe we can deprecate the onComplete(fn)
overload and remove the callback support later.
from observer-spy.
Thanks for the feedback @edbzn !
I thought about maybe another potential reason - whether using promises has any performance implications (microtasks queue wise)
So maybe callbacks, for sync Observables, could have slightly better performance? (not sure, just an unchecked thought) and that could be a reason to keep them...
Any thoughts/insights about that?
from observer-spy.
Interesting point 🤔
I don't think that this would have dramatic performance impact. I would worry more about tests that want to check if some operator like observeOn
is triggering a microtask or running synchronously... but it's an extreme edge case, in my opinion.
Otherwise, I'd focus more on simplicity and reducing the library's surface than the impact of an almost superfluous teeny-weeny micro tasky 😊
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 async await (promises).
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 1: ObserverSpy API - Methods vs getters HOT 7
- 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.