Skip to content

findByText returns [object Promise], hence erroring out with the error 'toContainText can be only used with Locator object' #513

Closed
@InduKrish

Description

@InduKrish

getByText - the below script with getByText() works fine
async checkActiveStatusdom(text) {

    const header = await this.screen.findByTestId('erow-GroupCode-0');
    console.log(" header" + header)
    const base = this.within(header).getByText("NEW HIRE")
    console.log("base value" + base);
    const check = this.within(header).getByText("check")
    console.log(" value " + check)
    await expect(base).toContainText(text);

}

however findByText - returns Error: toContainText can be only used with Locator object

async checkActiveStatusdom(text) {

   const header = await this.screen.findByTestId('erow-GroupCode-0');
   console.log(" header" + header)
   const base = this.within(header).findByText("LINEHOLDER")
   console.log("base value" + base);
   const check = this.within(header).findByText("check")
   console.log(" value " + check)
   await expect(base).toContainText(text);

console log:
headerLocator@query-by-test-id=["erow-GroupCode-0"]
base value[object Promise]
value [object Promise]

why getByText auto waits, but findByText returns no value, and returns Error: toContainText can be only used with Locator object.

From the previous ticket , #507

I was told that findby auto waits and getby does not auto wait, in this scenario it works differently.
Screen Shot 2022-09-19 at 4 52 10 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions