-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(cdk-experimental/testing): Refactor the ComponentHarness API #16234
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
Conversation
crisbeto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/cdk-experimental/testing/testbed/testbed-harness-environment.ts
Outdated
Show resolved
Hide resolved
67bc253 to
575f013
Compare
jelbourn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…angular#16234) Renames several APIs for readability
…#16234) Renames several APIs for readability
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Drawbacks to current API
QueryOptionsis confusing,undefined,true, andfalsemean different things forallowNull. The concept ofallowNullalso doesn't really apply when getting a list of elementsfindmethod is confusing as it doesn't actually find anything, it returns a function to find thingsNew API
The new API combines the variaous
loadmethods as well as theLocatorclass from the old API into a single class calledHarnessEnvironment. TheHarnessEnvironmentimplements two separate interfaces, one for test authors:HarnessLoader, and one for component harness authors:LocatorFactory. Both protractor and testbed have their own concrete implementations ofHarnessEnvironment, but they cannot be constructed directly. Users are required to construct them via acreatemethod which returns aHarnessLoaderinterface. This way only the methods that make sense for the test author are exposed to the test author.The
HarnessLoaderprovides methods to find newHarnessLoaders for sub-portions of the DOM and methods to createComponentHarnesses by searching for the corresponding host selector under its root element. EachComponentHarnessclass is required to specify its host selector, so the user doesn't have to.The
LocatorFactoryis the interface to theHarnessEnvironentavailable when extendingComponentHarness. It gives harness authors methods to create locator functions for findingTestElements andComponentHarnesses under its root element. It also provides a method to get aLocatorFactoryrooted at the document root, this can be used instead of theglobaloption from the old API.The methods described above for finding
HarnessLoadersComponentHarnessesand locator functions come in 3 different flavors (required, optional, and all). These different variants should be used instead of the oldallowNullsyntax. There is currently no replacement for{allowNull: undefined}but if we feel its important we can add a default variant of the method as well.Examples
Component harness author code
Test author code
Questions
locatormethod that behaves the same asrequiredLocatorfor unit tests but doesn't checkelement.isPresentin e2e tests?locatorForRequired? It reads a little nicer:this.locatorForRequired(MyCompHarness)