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.

Conditional rendering in visual tests

See original GitHub issue

How can I show conditionally rendered elements in the visual tests?

or…

How can get visual tests of my components, AFTER the play function has run?

Is there a possible way to do this?

or do I need to create an HOC that handles the state/clickaway… and passes a open=true/false to the inner component?

So I can just write a story for the LOC and switch out the open prop?

Canvas image

Snapshot image

Open State code

Open.play = async ({ canvasElement }) => {
  const canvas = within(canvasElement)
  await userEvent.click(canvas.getByTestId('ButtonMenuCheckbox-button'))
  const menu = await waitFor(
    () => screen.getByTestId('ButtonMenuCheckbox-menu--loaded'),
    { timeout: 1000, interval: 2000 }
  )
  waitFor(() => screen.getByTestId('ButtonMenuCheckbox-menu--loaded'), {
    timeout: 2000,
    interval: 2000,
  })
  expect(menu).toBeTruthy()
}

Note: There is a 100ms opacity transition on the popper menu that I am trying to also get around. Any tips on this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
averybrosscommented, Feb 18, 2022
image

Looks like that did the trick, but now my float: right is not working in Chromatic… only in Storybook (which I will eventually fix using your helper)

image
1reaction
averybrosscommented, Feb 18, 2022

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Conditional Rendering Techniques & Best Practices
Here are a few methods you can use to render React components: If Else conditional operator import React from 'react'; import ReactDOM from...
Read more >
Conditional Rendering in Vue - Telerik
Let's take a look at three Vue directives for conditional rendering: v-if, v-else and v-else-if. In this post, we will look at how...
Read more >
Visualforce to LWC: Conditional Rendering
Conditional Rendering is used to show or hide a particular block based on a condition. If you take a look at the below...
Read more >
Conditional rendering tactics for React components
A simple exploration and comparison of two tactics for handling conditionally rendering components in React.
Read more >
Conditional rendering in React | Ben Ilegbodu
It's more common, however, to do the conditional rendering within the context of the JSX. And probably the most common inline approach is...
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