Search code examples
javascriptreactjstypescriptreact-testing-librarytesting-library

How to read a button which contains text with asterisk in javascript


Can anyone please help me with the below statement

I am trying to get the element by text which contains asterisk

const readButton = test.getByText('Read the rules *');

Solution

  • Try

    test.getByText(/^Read the rules \*$/)
    

    To test regex you can use

    https://regex101.com/

    Docs about regex in testing-library are here

    https://testing-library.com/docs/queries/about/

    Second option:

    test.getByText(content => content === 'Read the rules *');