-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Examples or reference materials. #25
Comments
Regarding the first question: yes, in light of this issue, from yesterday, I've added a task to my TODO list to improve the documentation. It's grown over time and could do with being reorganised. And, yes, the examples could be improved. As for the second, I will check out the example you've referenced a little later. Thanks for raising the issue. |
@cartant Did you ever get round to looking at this for me? |
I've had a look at your example. Thanks for the effort that you've put into it. However, I think tests that involve schedulers should use the When testing with schedulers you have two options:
I would do something like this: describe('Delayer', () => {
it(
'should complete when it receives a payload with a delay value of 4 seconds or greater.',
marbles(m => {
const values = {
a: { value: 'alpha', delay: 10 },
b: { value: 'beta', delay: 20 },
c: { value: 'charlie', delay: 30 },
d: { value: 'delta', delay: 40 }
}
const producer = m.hot('^a-b--c---d|', values)
const expected = m.hot('^-a--b---c|', values)
m.bind();
const observable = delayer(producer)
m.expect(observable).toBeObservable(expected)
})
)
}) With module.exports = subject =>
Observable.from(subject)
.takeWhile(x => x.delay < 40)
.concatMap(x => Observable.of(x).delay(x.delay))
.do(console.log) The clear benefit is that the expected marble diagram includes the delays. (Note that you will need to reduce your I've created a |
@cartant Thanks so much for taking the time, this was SUPER helpful. |
I don't think you will be able to change it. The maximum frame of 750 is a constant and it's passed to the Around the time I published |
Oh, so we can't test anything that is more than 3/4 of a second delayed? What is the motive for having this threshold? |
The Basically, each char is 10 frames and the maximum of 750 is essentially based on that. Who wants to look at and align marble diagrams containing more than 75 characters? There has been some discussion regarding using OJ's Do you have a large number of tests that require specific, long durations that cannot be parameterised in the tests? That is, you cannot specify a specific, shorter delay for testing purposes? If you have only a few, you might want to test using just the |
Thanks for the references, I have a bit reading to do no doubt. I'm a little out of touch with the movement in the RxJS space, clearly In our project we have some timings that are part of the characteristics under test. If the 75 char limit is an arbitrary limit based on assumed use cases maybe we could make it configurable, or is there some technical reason we would want to limit it to a specific length? |
There's no reason why it shouldn't be more configurable. It's just that it was built to test the RxJS library and it does that. The authors didn't need it to do anything else, so it doesn't - YAGNI and all that. I'll make an note to have a closer look at the internals, later, to see if there's any way I can just clobber it. I doubt it would be a bigger hack than |
Nice! Let me know how you get on ;) Thanks again! |
Actually, it'd be pretty simple to add this to |
@cartant So I've been jamming a bit with |
Passing OJ's However, you'd want to bind the default schedulers to the instance of OJ's scheduler. I guess you could try passing and instance of OJ's scheduler to the Regarding
And decided that - whilst it might see me, too, going to hell - it would make my life a lot easier when it comes to deeply nested schedulers. The code in Jay's comment might make things a little clearer. |
What I would really like is to be able to specify the scheduler in the call to Being able to do that might save me from eternal damnation. 🔥 😄 🔥 |
@cartant I may need an invitation to see that slack comment? I'm not in that slack community. Or is that all the code you pasted there? |
If you want an invite, just ask Tracy Lee. See this tweet or you could email her: tracy@thisdot.co And, yep, I pasted the whole comment. |
Oh you did paste the whole thing...? Not even slightly clearer though I'm afraid, I clearly require quite a bit of study of the RxJS innards. That snippet looks pretty crazy hacky though 😂 |
I've published 2.4.1 which adds a There's a fixture that demonstrates the usage: it("should support reframing", marbles((m) => {
m.reframe(100, 10000);
const duration = m.time("--|");
expect(duration).to.equal(200);
const source = m.cold("--(a|)");
const expected = m.cold("----(a|)");
m.expect(source.delay(duration, m.scheduler)).toBeObservable(expected);
}));
The clobbering is restored after the context is torn down, so the reframing is local to each test. If you always want to use a particular framing configuration, you could create a module and could export a wrapped import { marbles as _marbles } from "rxjs-marbles/jest";
export function marbles(func: (m: Context, ...rest: any[]) => any): any {
return _marbles((m: Context, ...rest: any[]) => {
m.reframe(100, 10000);
return func(m, ...rest);
});
} Closing this. When RxJS v6 is released, I'll release a version of |
You sir, are an absolute legend! 🎉 |
Firstly, many thanks for some awesome work here.
I have just spent the morning getting everything working with our Jest setup. Struggled a bit TBH. I spent a lot of time hopping between blogs and docs trying to piece together a decent real world test example.
My output is here: https://github.com/hally9k/rxjs-marbles-jest-example
This issue is really 2 questions:
Should we add some examples like this to the source or links to the readme to help future noobs like myself?
Does my output referenced serve as good example or have I missed a better way to do this? (It doesn't feel super clean the way that I am mocking delay...) 🤔
The text was updated successfully, but these errors were encountered: