Skip to content
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

feat(Router): Import RouterTestingModule when stubs are enabled #488

Merged
merged 8 commits into from
Sep 29, 2021

Conversation

AnthonyLenglet
Copy link
Contributor

@AnthonyLenglet AnthonyLenglet commented Sep 27, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #487

What is the new behavior?

createRoutingFactory now imports RouterTestingModule when stubs are enabled, then adds the necessary stubs and overrides, thus adding the missing inputs and methods from router related features

Does this PR introduce a breaking change?

[ ] Yes
[x] No

createRoutingFactory had an undocumented mockRouterLink that has been removed as it is no longer needed

Other information

@@ -14,15 +14,32 @@ import { RouterLink } from '@angular/router';
})
export class RouterLinkDirectiveStub {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Now that I'm thinking about it, I can't remember why we have a stub here. Can you try to use the original directive, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can gather, it looks like I can't just do moduleMetadata.declarations.push(RouterLink); instead of moduleMetadata.declarations.push(RouterLinkStub);

since angular 9, you need to import the module of the library directly
angular/angular#37047 (comment)

so turns out I need to import RouterTestingModule along with the other stubs when they are enabled

I was able to make it work but I needed to mock the serializeUrl function in the routerStub, as angular was trying to parse the url using it internally

serializeUrl(): string {
  return '/';
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure if the routerStub is still needed since I'm now importing RouterTestingModule, it looks like it should really just stub ActiveRoute

@NetanelBasal
Copy link
Member

@AnthonyLenglet can you summarize the change, plesae?

@AnthonyLenglet AnthonyLenglet changed the title feat(RouterLink): Add missing inputs to the stub feat(Router): Import RouterTestingModule when stubs are enabled Sep 29, 2021
@AnthonyLenglet
Copy link
Contributor Author

Just updated the initial PR post with a new summary

createRoutingFactory now imports RouterTestingModule when stubs are enabled, then adds the necessary stubs and overrides, thus adding the missing inputs and methods from router related features

@NetanelBasal
Copy link
Member

@AnthonyLenglet tests are failing.

RouterTestingModule is imported, meaning that he is now the one testing this
@AnthonyLenglet
Copy link
Contributor Author

oh right, I removed those from the jasmine tests, but forgot to remove them from jest, sorry about that !

@NetanelBasal NetanelBasal merged commit 5308c26 into ngneat:master Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants