-
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
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
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
QueryOptions
is confusing,undefined
,true
, andfalse
mean different things forallowNull
. The concept ofallowNull
also doesn't really apply when getting a list of elementsfind
method is confusing as it doesn't actually find anything, it returns a function to find thingsNew API
The new API combines the variaous
load
methods as well as theLocator
class from the old API into a single class calledHarnessEnvironment
. TheHarnessEnvironment
implements 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 acreate
method which returns aHarnessLoader
interface. This way only the methods that make sense for the test author are exposed to the test author.The
HarnessLoader
provides methods to find newHarnessLoader
s for sub-portions of the DOM and methods to createComponentHarness
es by searching for the corresponding host selector under its root element. EachComponentHarness
class is required to specify its host selector, so the user doesn't have to.The
LocatorFactory
is the interface to theHarnessEnvironent
available when extendingComponentHarness
. It gives harness authors methods to create locator functions for findingTestElement
s andComponentHarness
es under its root element. It also provides a method to get aLocatorFactory
rooted at the document root, this can be used instead of theglobal
option from the old API.The methods described above for finding
HarnessLoader
sComponentHarnesses
and locator functions come in 3 different flavors (required, optional, and all). These different variants should be used instead of the oldallowNull
syntax. 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
locator
method that behaves the same asrequiredLocator
for unit tests but doesn't checkelement.isPresent
in e2e tests?locatorForRequired
? It reads a little nicer:this.locatorForRequired(MyCompHarness)