Skip to content

React Testing Library #30

Open
Open
@alanjohnson

Description

@alanjohnson

My project requires test coverage, but RTL never renders any of the children in XMasonry. I understand that XMasonry does 3 renders, but i never can seem to get it to finish any rendering to be able to run a test on any of the contents.

i.e. what do we need to do to get a basic test like this to pass?

import React from 'react';
import { render, screen } from '@testing-library/react';
import { XMasonry, XBlock } from 'react-xmasonry';

test('Selecting elements in Masonry', async () => {
  render(
    <XMasonry>
      <XBlock>
        <div className="card">
          <h1>Simple Card</h1>
        </div>
      </XBlock>
      <XBlock width={2}>
        <div className="card">
          <h1>Wider card</h1>
        </div>
      </XBlock>
    </XMasonry>
  );
  const testItem = await screen.findByText('Simple Card');
  expect(testItem).toBeInTheDocument();
});

Now, i've been able to get it to pass by using waitFor()... BUT, that seems like a false positive, since i can say waitFor - "THIS IS NOT THERE", and it will pass an assertion that it is there. same goes for trying to nest it inside requestAnimationFrame.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions