Unit testing dialogs not intuitive
See original GitHub issueWhile writing unit tests for a function that handles a angular material 2 dialog using the example code from material 2 i run into problems. I’m a Jasmine newbie but I didn’t had problems to write unit test before. I have to test the result of the afterClose function but i can’t get the handle on dialogRef.
For sure there is a workaround but since this was the first function that was really hard to test and someone liked my post on stackoverflow about it maybe refactoring could make it easier ? http://stackoverflow.com/questions/42852816/unit-testing-angular-material-2-dialogs
let dialogRef = this.dialog.open(ExtractPageDialog, {
width: this.EXPORT_DIALOG_WIDTH,
data: {
document: this.document
}
});
dialogRef.afterClosed().subscribe((result: any) => {
if (result) {
let fileId = this.document.fileId;
this.docProvider.extractPage(this.document.fileId, result.fromPage, result.toPage).subscribe(() => {
() => { //totest },
(error) => { //totest }
});
} else {
//totest
}
});
DOCS: https://material.angular.io/components/component/dialog
Proposal, change the example to be easier to test:
dialogRef.afterClosed().subscribe(this.functionName);
functionName(result: any) {
if (result) {
let fileId = this.document.fileId;
this.docProvider.extractPage(this.document.fileId, result.fromPage, result.toPage).subscribe(() => {
() => { //totest },
(error) => { //totest }
});
} else {
//totest
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Yes, User Prompts and Unit Tests Can Co-Exist
Nevertheless, it's not true that the presence of user prompts is an absolute bar to unit testing. Depending on your implementation, unit testing ......
Read more >Why practicing DRY in tests is bad for you - DEV Community
I'm going to share my point of view on practicing DRY in unit tests and why I think it is bad for you....
Read more >Testing Runtime Permissions: Lessons Learned
Permission model was not very user-friendly before Marshmallow: every time ... First, let's write a test that will simply verify that the request...
Read more >Painless Unit Testing with Kotlintest & Mockk | Zuhaib Ahmad
In this post, let's understand why unit tests serve as the backbone of successful products and learn a new way of writing tests...
Read more >Build and Test Modal using React features and DOM events ...
This series IS NOT about setting up testing environments for React — The goal is to help you build intuition on what to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Even though this issue has been closed I must say I have never seen such a complex and non-understandable unit tests definition with so many generic variables. overlayContainerElement, viewContainerFixture, ComponentWithChildViewContainer etc…
You have to know each class and its definition perfectly to understand the code. Who would need comments anyways, right?
Angular 6.1.1 Material 6.4.3
40+ lines of boiler plate. I learn more about Angular when writing tests than anything else!
Very simple “save” and “cancel” test for
EditDialogComponent
: