state.md
December 8, 2023 · View on GitHub
🏠 → Documentation → Built-In Functionality → state
Other Predicates: attributes ・ callLifeCycleHook ・call ・clicked ・debug ・detectChanges ・emit ・ provider ・state ・waitFakeAsync
This predicate sets the specified component state(s) on its associated target(s) and runs change detection afterwards.
Signature
state(propertyMap: PropertiesOf<Component> | PropertiesOf<Component>[]);
where the type constraint
Componentis referring to the component-type of the subject associated with this predicate.
Example
class the {
static GreetingLabel() {
return get('h2');
}
static PaymentOptions() {
return getAll(ToggleButtonComponent);
}
static BuyButton() {
return getAll(ToggleButtonComponent);
}
}
it('should render the correct welcome message', () => {
When(host)
.has(state({ userName: 'Ann' }))
.expect(the.GreetingLabel)
.to(haveText('Welcome Ann!'));
});
it('should submit a valid person object when the form is valid', () => {
When(the.PaymentOptions)
.have(
state([
// 1) debit, 2) paypal, 3) cash
{ selected: true },
{ selected: false },
{ selected: false },
]),
)
.and(the.BuyButton)
.gets(clicked())
.expect(host)
.to(haveCalled(injected(DebitService), 'initPayment'));
});