Skip to content

fix: fix config for testing with zoneless Angular #535

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

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

mikeshtro
Copy link

This PR fixes zoneless flag in the configure function. I tried to use the configure function with zoneless flag

function setup() {
  configure({ zoneless: true });
  return render(MyComponent);
}

but I got error Unexpected value 'undefined' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.

This is because provideZonelessChangeDetection is incorrectly used inside imports instead of providers.

@timdeschryver
Copy link
Member

timdeschryver commented Jul 12, 2025

Thanks for raising this PR @mikeshtro
I also got a question. Do you think it's useful to also add this config to the render method, because currently it's set at the global level using the configure method.
My reasoning is that either you use zoneless or not for the whole application, and thus it isn't needed to set at test-level.

@mikeshtro
Copy link
Author

My original idea was to add it to the render method, because I consider it to be the main method, how I setup my tests when using testing library.
But as you described we use zoneless or not for the whole application and so I think the configure method is enough, because it covers the main scenario. If we want to configure it at test-level we can always provide it manually

render(MyComponent, {
  providers: [provideZonelessChangeDetection()]
})

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

Thanks @mikeshtro !

@timdeschryver timdeschryver merged commit 06bb84e into testing-library:beta Jul 14, 2025
6 checks passed
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.

2 participants