attributes.md
December 8, 2023 · View on GitHub
🏠 → Documentation → Built-In Functionality → attributes
Other Predicates: attributes ・ callLifeCycleHook ・ call ・ clicked ・ debug ・ detectChanges ・ emit ・ provider ・ state ・ waitFakeAsync
This predicate sets the specified attribute(s) on its associated target(s) and runs change detection afterwards.
Signature
attributes(attrMap: PropertiesOf<Html> | PropertiesOf<Html>[]);
where the type constraint
Htmlis referring to the HTML-type of the subject associated with this predicate.
Example
class the {
static NameInput() {
return get<HTMLInputElement>('input');
}
static Inputs() {
return getAll<HTMLInputElement>('input');
}
static SubmitButton() {
return get('.btn-submit');
}
}
it('should clear the name-input text on clear-button click', () => {
When(the.NameInput)
.has(attributes<HTMLInputElement>({ value: 'some text' }))
.and(host)
.calls(componentMethod, 'clearText')
.expect(the.NameInput)
.to(haveAttributes({ value: '' }));
});
it('should submit a valid person object when the form is valid', () => {
When(the.Inputs)
.have(
attributes<HTMLInputElement>([
{ value: 'Ann' },
{ value: 'Smith' },
{ value: '42' },
]),
)
.and(the.SubmitButton)
.gets(clicked())
.expect(host)
.to(
haveEmitted('finish', {
arg: { firstName: 'Ann', lastName: 'Smith', age: 42 },
}),
);
});