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

fix: Use setInput for component properties in Angular component tests #27775

Closed
wants to merge 2 commits into from

Conversation

cg-roling
Copy link

@cg-roling cg-roling commented Sep 8, 2023

This is an alternative fix for #23591, where ngOnChanges is not being called when mounting a component using the Class syntax.

ComponentRef.setInput was introduced in Angular 14.1.

The original fix (#23596) calls ngOnChanges manually to make up for the fact that properties are assigned directly to the component, bypassing Angular change detection.

That fix, however, causes an issue where subsequent calls to componentRef.setInput in the test will be considered the first change, and will not include previousValue.

Instead, if we use setInput to set component properties when mounting, ngOnChanges is called automatically by Angular, and future calls to setInput track changes properly.

Note: I didn't figure out how to run the tests modified in the original bug. They should still pass. It also might be worth adding a test for the ngOnChanges behavior. If someone could let me know how to run those tests, I would be happy to add it!

@CLAassistant
Copy link

CLAassistant commented Sep 8, 2023

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@cg-roling cg-roling changed the title Set input Use setInput for component properties in Angular component tests Sep 8, 2023
@cg-roling cg-roling marked this pull request as ready for review September 8, 2023 17:42
@cypress
Copy link

cypress bot commented Sep 8, 2023

5 failed and 23 flaky tests on run #50895 ↗︎

5 28095 1345 0 Flakiness 23

Details:

Use Object.assign for non-inputs
Project: cypress Commit: 4609f15e78
Status: Failed Duration: 34:55 💡
Started: Sep 8, 2023 5:53 PM Ended: Sep 8, 2023 6:28 PM
Failed  runner/ct-framework-errors.cy.ts • 1 failed test • app-e2e

View Output Video

Test Artifacts
Angular 13 > error conditions Test Replay Output Screenshots
Failed  angular.cy.ts • 4 failed tests • webpack-dev-server

View Output Video

Test Artifacts
angular-13 > test behaviors > should mount a passing test Test Replay Output Screenshots
angular-13 > test behaviors > should live-reload on src changes Test Replay Output Screenshots
angular-13 > test behaviors > should show compilation errors on src changes Test Replay Output Screenshots
angular-13 > test behaviors > should detect new spec Test Replay Output Screenshots
Flakiness  commands/net_stubbing.cy.ts • 1 flaky test • 5x-driver-firefox

View Output Video

Test Artifacts
network stubbing > waiting and aliasing > can spy on a 304 not modified image response Output
Flakiness  e2e/origin/commands/assertions.cy.ts • 1 flaky test • 5x-driver-firefox

View Output Video

Test Artifacts
cy.origin assertions > #consoleProps > .should() and .and() Output
Flakiness  cypress/cypress.cy.js • 3 flaky tests • 5x-driver-firefox

View Output Video

Test Artifacts
... > correctly returns currentRetry Output
... > correctly returns currentRetry Output
... > correctly returns currentRetry Output
Flakiness  runs.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
App: Runs > no internet connection > shows correct message on connect project modal Test Replay Output Screenshots
Flakiness  cypress-in-cypress.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
Cypress in Cypress > restarts browser if there is a before:browser:launch task and there is a change on the config Test Replay Output Screenshots

The first 5 flaky specs are shown, see all 11 specs in Cypress Cloud.

Review all test suite changes for PR #27775 ↗︎

@cg-roling
Copy link
Author

Angular 13 failures are... unfortunate 😬. Is that something we would want to try to work around?

@jennifer-shehane jennifer-shehane changed the title Use setInput for component properties in Angular component tests fix: Use setInput for component properties in Angular component tests Jan 19, 2024
@jennifer-shehane jennifer-shehane added the CT Issue related to component testing label Jan 19, 2024
@cypress-app-bot
Copy link
Collaborator

This PR has not had any activity in 180 days. If no activity is detected in the next 14 days, this PR will be closed.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Jul 18, 2024
@cypress-app-bot
Copy link
Collaborator

This PR has been closed due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CT Issue related to component testing stale no activity on this issue for a long period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants