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
Marble testing doc additions #4522
Marble testing doc additions #4522
Conversation
Pull Request Test Coverage Report for Build 8193
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits.
doc/marble-testing.md
Outdated
- `hot(marbleDiagram: string, values?: object, error?: any)` - creates a ["hot" observable](https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339) (like a subject) that will behave as though it's already "running" when the test begins. An interesting difference is that `hot` marbles allow a `^` character to signal where the "zero frame" is. That is the point at which the subscription to observables being tested begins. | ||
- `cold(marbleDiagram: string, values?: object, error?: any)` - creates a ["cold" observable](https://medium.com/@benlesh/hot-vs-cold-observables-f8094ed53339) whose subscription starts when the test begins. | ||
- `expectObservable(actual: Observable<T>).toBe(marbleDiagram: string, values?: object, error?: any)` - schedules an assertion for when the TestScheduler flushes. Give `subscriptionMarbles` as parameter to change the schedule of subscription and unsubscription. If you don't provide the `subscriptionMarbles` parameter it will subscribe at the beginning and never unsubscribe. Read below about subscription marble diagram. | ||
- `expectObservable(actual: Observable<T>, subscriptionMarbles: string).toBe(marbleDiagram: string, values?: object, error?: any)` - schedules an assertion for when the TestScheduler flushes. Give `subscriptionMarbles` as parameter to change the schedule of subscription and unsubscription. If you don't provide the `subscriptionMarbles` parameter it will subscribe at the beginning and never unsubscribe. Read below about subscription marble diagram. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter is optional: subscriptionMarbles?: string
doc/marble-testing.md
Outdated
expectObservable(repeatingStream$, unsub).toBe(results); | ||
}); | ||
}) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a complete example? results
is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whiteinge ... can you also add a example of using the subscription marbles to delay the subscription?
For example, given a hot source, you can subscribe to it more than once and verify the results:
testScheduler.run(({ hot, expectObservable }) => {
const source = hot('--a--a--a--a--a--a--a--');
const sub1 = ' --^-----------!';
const sub2 = ' ---------^--------!';
const expect1 = ' --a--a--a--a--';
const expect2 = ' -----------a--a--a-';
expectObservable(source, sub1).toBe(expect1);
expectObservable(source, sub2).toBe(expect2);
});
Why: This is a complete example, as requested, and also more plain to demonstrate just the one param.
3024b3e
to
a44db32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Generated by 🚫 dangerJS |
Will the change log bot ignore those two fixup commits? Or should I rebase them into their respective initial commits? |
All of the commits in here are so closely related that I would expect the person merging to squash them, so I wouldn't worry about it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits, and a request for one more example (I provided one, if that helps).
doc/marble-testing.md
Outdated
expectObservable(repeatingStream$, unsub).toBe(results); | ||
}); | ||
}) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whiteinge ... can you also add a example of using the subscription marbles to delay the subscription?
For example, given a hot source, you can subscribe to it more than once and verify the results:
testScheduler.run(({ hot, expectObservable }) => {
const source = hot('--a--a--a--a--a--a--a--');
const sub1 = ' --^-----------!';
const sub2 = ' ---------^--------!';
const expect1 = ' --a--a--a--a--';
const expect2 = ' -----------a--a--a-';
expectObservable(source, sub1).toBe(expect1);
expectObservable(source, sub2).toBe(expect2);
});
Co-Authored-By: whiteinge <seth@eseth.com>
Example courtesy of @benlesh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also move this document to docs_app/content/guide
(not 100% sure about the path) and make a minor adjustment in the navigation.json
file. That this change will directly be in the new docs! If you need any kind of help with this, just let me know. I would love to have this in the new docs, so thank you very much!
Also remove the redundant docs so contributors know where to look for the up-to-date canonical docs.
@jwo719 done. Thanks for the pointer. I didn't realize there was a spot for those docs in the guide and that's a much better (and nicer looking) place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic addition! Thank you.
Description:
Additions and adjustments to the marble testing documentation. These additions emphasize the async helper functions, and also make the subscriptionMarbles parameter more explicit.
Related issue (if exists):
Closes #4521.