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(core): allow to throw on unknown elements in tests #45479

Closed

Conversation

cexbrayat
Copy link
Member

@cexbrayat cexbrayat commented Mar 30, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Feature

What is the current behavior?

In a test, when using an unknown element in a template, we just get a console error.

Issue Number: #36430

What is the new behavior?

Allows to provide a TestBed option to throw on unknown elements in templates:

getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting(),
  { errorOnUnknownElements: true }
);

Does this PR introduce a breaking change?

The default value of throwOnUnknownElement is false, so this is not a breaking change.

  • Yes
  • No

@google-cla
Copy link

@google-cla google-cla bot commented Mar 30, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch 2 times, most recently from 68cd385 to 18af293 Compare Mar 30, 2022
@dylhunn dylhunn added the comp: core label Mar 30, 2022
@ngbot ngbot bot added this to the Backlog milestone Mar 30, 2022
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

@cexbrayat thanks for creating this PR! 👍
The changes look great, just left a few minor comments.

packages/core/test/acceptance/ng_module_spec.ts Outdated Show resolved Hide resolved
packages/core/src/render3/index.ts Outdated Show resolved Hide resolved
packages/core/src/render3/instructions/element.ts Outdated Show resolved Hide resolved
packages/core/testing/src/r3_test_bed.ts Outdated Show resolved Hide resolved
@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch 7 times, most recently from 052f49f to 67ce006 Compare Apr 5, 2022
@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch 3 times, most recently from 464a47e to ce828a7 Compare Apr 19, 2022
@cexbrayat cexbrayat marked this pull request as ready for review Apr 19, 2022
goldens/public-api/core/testing/index.md Outdated Show resolved Hide resolved
packages/core/testing/src/test_bed_common.ts Outdated Show resolved Hide resolved
packages/core/testing/src/test_bed_common.ts Outdated Show resolved Hide resolved
packages/core/testing/src/r3_test_bed.ts Outdated Show resolved Hide resolved
@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch 2 times, most recently from 6a02152 to 6b556e3 Compare Apr 20, 2022
@AndrewKushnir AndrewKushnir added action: review target: major and removed state: WIP labels Apr 20, 2022
@AndrewKushnir AndrewKushnir removed this from the Backlog milestone Apr 20, 2022
@AndrewKushnir AndrewKushnir added this to the v14-candidates milestone Apr 20, 2022
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

@cexbrayat the changes look good, thanks Cedric!

We've discussed this change during the team sync and this looks like the approach we want to take. This approach allows us to enable this by default (in one of the next major versions) and use this mechanism for opt-out.

@pullapprove pullapprove bot requested review from alxhub and AndrewKushnir Apr 22, 2022
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

reviewed-for: public-api

Copy link
Member

@jelbourn jelbourn left a comment

LGTM

Reviewed-for: public-api

goldens/public-api/core/testing/index.md Outdated Show resolved Hide resolved
@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch 2 times, most recently from 4129e51 to 5e2a608 Compare Apr 29, 2022
@cexbrayat
Copy link
Member Author

@cexbrayat cexbrayat commented Apr 29, 2022

We agreed with @AndrewKushnir that errorOnUnknownElements was probably a better name, as @atscott and @jelbourn suggested. I updated the PR to use errorOnUnknownElements instead of throwOnUnknownElements

Allows to provide a TestBed option to throw on unknown elements in templates:

```ts
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting(), {
    errorOnUnknownElements: true
  }
);
```

The default value of `errorOnUnknownElements` is `false`, so this is not a breaking change.
@cexbrayat cexbrayat force-pushed the feat/throw-on-unknown-element branch from 5e2a608 to 1d169e8 Compare Apr 29, 2022
@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Apr 29, 2022

Presubmit (note: this change would also require this update in g3) + TGP.

@AndrewKushnir AndrewKushnir added feature action: presubmit and removed action: review labels Apr 29, 2022
@AndrewKushnir AndrewKushnir removed request for alxhub and dylhunn Apr 30, 2022
@AndrewKushnir AndrewKushnir added action: merge and removed action: presubmit labels Apr 30, 2022
@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Apr 30, 2022

FYI, the presubmit went well and I'm adding this PR to the merge queue.

@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented May 2, 2022

This PR was merged into the repository by commit 6662a97.

@dylhunn dylhunn closed this in 6662a97 May 2, 2022
dylhunn added a commit to dylhunn/angular that referenced this issue May 2, 2022
dylhunn added a commit that referenced this issue May 2, 2022
@dylhunn dylhunn reopened this May 2, 2022
@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented May 2, 2022

Rolled this back temporarily because I didn't see the g3 patch above. I will roll forward again and sync with the patch.

@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented May 2, 2022

This PR was merged into the repository by commit e702caf.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Jun 2, 2022

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge comp: core feature target: major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants