question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add "id" attribute for testing purpose?

See original GitHub issue

Hello, I do not find a good way for adding unique “id” attribute for the toast and toast body. Currently, I work within className but would be great to have optional parameter id. Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
JulianoGTZcommented, Nov 13, 2019

The End to end test has implemented with Cypress?

Where I work, the shared function was implemented like this

Cypress.Commands.add('checkToastMessage', (message) => {
    cy.get('.Toastify__toast').should('contain', message);
    cy.closeAllAlertMessages();
});

Cypress.Commands.add('closeAllAlertMessages', () => {
    cy.get('.Toastify__close-button').click({ multiple: true, force: true });
});
3reactions
PierrickG34commented, Mar 15, 2021

Hi, thanks for your example @JulianoGTZ. We can improve it with toastId option like this :

  1. Create toast : toast.success("hello" , {toastId: "my-toastId"});

  2. Cypress command for check :

Cypress.Commands.add('checkToastMessage', (toastId, message) => {
  cy.get(`[id=${toastId}]`).should('contain', message);
  // ...
});
  1. Use it : cy.checkToastMessage("my-toastId", "hello")
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the data-testid attribute in testing? - Educative.io
data-testid is an attribute used to identify a DOM node for testing purposes. It should be used as a handler to the test...
Read more >
HTML - The id attribute - W3Schools
The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with...
Read more >
Is it good practice to give html elements id attributes that are ...
CONS As the developer a am highly skeptical about adding id attributes that serve no functional purpose. I think it clutters the code....
Read more >
HTML Id Attributes - GeeksforGeeks
The id attribute is a unique identifier that is used to specify the document. It is used by CSS and JavaScript to perform...
Read more >
Data-* attributes. Hook your automated tests on proper selectors.
ID attribute. The purpose of ID is to have a unique reference that is not repeated on a page. So if you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found