'How to test tr(table row) has onclick and style={{ cursor: "pointer" }} in react testing library
<tbody data-testid="offers-list-tablebody">
{ offers.map((Offer) => (
<tr onClick={this.handleTermsAndConditionsBtnClick} style={{ cursor: "pointer" }} key={index}>
}
I tried in this way
const tableBody = list.find("[data-testid='offers-list-tablebody']");
const tableRow1 = tableBody.childAt(0);
const clickElement1 = (tableRow1.key());
expect(clickElement1.onclick).toBeTruthy();
expect(clickElement1).toHaveStyle("cursor: pointer");
The error is Property "onclick does not exist on type string" and it is hsowing value of index when tested. How to test this?
Solution 1:[1]
it is because you are assigning clickElement1 to tableRow1.key() which returns a string.
Replace clickElement with tableRow1 like below
expect(tableRow1.onclick).toBeTruthy();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Samantha |
