React-toastify: How to add "id" attribute for testing purpose?

Created on 14 Dec 2018  路  10Comments  路  Source: fkhadra/react-toastify

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

Most helpful comment

I'll consider adding this for the next patch release

All 10 comments

Hey @CrispusDH,

Could you share which kind of test you would like to implement ?

I write e2e UI automation tests using Protractor framework. Currently, I'm using className and bodyClassName for identifying Toast element and text inside. But, best practice is to add id attributes and use them. @fkhadra , thanks for fast response.

@fkhadra , any updates? :)

Hello @CrispusDH,

The end of the year is quite busy for me at work 馃槥 . I'll get back to you as soon as possible, sorry for that.

@fkhadra , If you need some more information just let me know. Thanks

Close, due to @fkhadra inactivity

I want this feature too? QA is having a tough time checking for toastify messages.

I'll consider adding this for the next patch release

Hi all,

I have a suggestion for this one.
If you define an id on ToastContainer, this id will be used:

<ToastContainer id="foo"> -> <div id="foo" {...othersProps}>...<div/>

For the toast, I suggest to use the toastId as the htmlid:

toast('hello', {
  toastId: 'xxx'
});
<div id="xxx" {...othersProps}>...<div/>

Is that what you are looking for ?

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 });
});
Was this page helpful?
0 / 5 - 0 ratings