Coder Social home page Coder Social logo

Comments (4)

cmorten avatar cmorten commented on August 17, 2024 2

As solution to this specific use-case, is something like…

test('some executions after the message is removed works as expected', async () => {
  render(<SomeComponent />);
  const targetElement = getByText('some message');

  const isRemovedPromise = waitForElementToBeRemoved(targetElement);

  // an action to remove the message
  await user.click(getByRole('button', { name: 'remove message' }));

  // wait until the message is removed
  await isRemovedPromise;

  // It is explicit that the following code is executed after the "some message" is removed
  doSomething();
})

passable? (Some care needed to handle the dangling promise with a subtle change if being strict with resource cleanup and for if the click throws)

from dom-testing-library.

AngusMacrae avatar AngusMacrae commented on August 17, 2024 1

The problem with your suggestion would be that it would require everyone to make an additional manual assertion like you have at the start of the test, to ensure the element exists before proceeding.

Otherwise if changed as suggested, simply doing

waitForElementToBeRemoved(screen.queryBy...)

Would no longer fail if the element never existed in the first place.

So basically it would be making the API less flexible, just for the sake of avoiding one extra check.

from dom-testing-library.

tnyo43 avatar tnyo43 commented on August 17, 2024 1

@cmorten
Thank you for your suggestion! That works on my cases.

from dom-testing-library.

tnyo43 avatar tnyo43 commented on August 17, 2024

it would be making the API less flexible

I think my suggestion makes the API requiring more effort, but also MORE flexible 😉


So how can we ensure that the element exists at the start of the waitForElementToBeRemoved?
If we use await waitForElementToBeRemoved(screen.queryBy...) after any actions to remove a element, we must consider the possibility that the element have already removed at the start of it unless we know it takes much time to complete the removing actions.

We should consider more carefully about the timing of asynchronous processing.

from dom-testing-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.