How to use the @testing-library/react.screen.findByText function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kentcdodds / react-testing-library-examples / src / __tests__ / react-lazy-and-suspense.js View on Github external
test('app renders stuff!', async () => {
  // this is how you render a component that has it's own suspense.
  // no need to render our own suspense in the test.
  render()
  const lazyElement = await screen.findByText(/i am lazy/i)
  expect(lazyElement).toBeInTheDocument()
})
github openfun / marsha / src / frontend / components / TimedTextListItem / index.spec.tsx View on Github external
active_stamp: 28271937429,
              id: '42',
              is_ready_to_show: true,
              language: 'fr',
              mode: timedTextMode.SUBTITLE,
              title: 'foo',
              upload_state: uploadState.READY,
              url: 'https://example.com/timedtexttrack/42',
              video: '142',
            }}
          />,
        ),
      ),
    );

    await screen.findByText('French');
    screen.getByText((content) => content.startsWith('Ready'));
    // No polling takes place as the track is already READY
    expect(
      fetchMock.called('/api/timedtexttracks/1/', { method: 'GET' }),
    ).not.toBeTruthy();
  });
github openfun / marsha / src / frontend / components / Dashboard / index.spec.tsx View on Github external
it('renders', async () => {
      const mockVideo: any = {
        id: 'dd44',
        thumbnail: null,
        timed_text_tracks: [],
        upload_state: uploadState.PROCESSING,
      };

      render(
        wrapInIntlProvider(
          }>
            
          ,
        ),
      );
      await screen.findByText('Dashboard');
      await screen.findByTitle('dd44');
    });
  });
github openfun / marsha / src / frontend / components / VideoPlayer / index.spec.tsx View on Github external
it('allows video download when the video object specifies it', async () => {
    mockIsMSESupported.mockReturnValue(false);
    appData.video!.show_download = true;

    render(wrapInIntlProvider());

    await screen.findByText(/Download this video/i);
    screen.getByText('Show a transcript');
  });
github openfun / marsha / src / frontend / components / TimedTextCreationForm / index.spec.tsx View on Github external
fireEvent.click(button);

    expect(
      fetchMock.calls('/api/timedtexttracks/', { method: 'POST' }).length,
    ).toEqual(1);
    expect(
      fetchMock.lastCall('/api/timedtexttracks/', { method: 'POST' })![1],
    ).toEqual({
      body: '{"language":"fr","mode":"st"}',
      headers: {
        Authorization: 'Bearer some token',
        'Content-Type': 'application/json',
      },
      method: 'POST',
    });
    await screen.findByText('Upload form: timedtexttracks 42');
  });
github openfun / marsha / src / frontend / components / VideoPlayer / index.spec.tsx View on Github external
{
        active_stamp: 1549385921,
        id: 'ttt-1',
        is_ready_to_show: true,
        language: 'fr',
        mode: 'st',
        upload_state: 'ready',
        url: 'https://example.com/timedtext/ttt-1.vtt',
      },
    ]);

    const { container } = render(
      wrapInIntlProvider(),
    );

    await screen.findByText('Show a transcript');
    expect(container.querySelector('option[value="ttt-1"]')).not.toBeNull();
  });
github openfun / marsha / src / frontend / components / DashboardTimedTextManager / index.spec.tsx View on Github external
render(
      wrapInIntlProvider(
        wrapInRouter(
          ,
        ),
      ),
    );

    screen.getByText('Our title');

    await screen.findByText('French');
    screen.getByText('English');
  });
});
github openfun / marsha / src / frontend / components / DashboardTimedTextPane / index.spec.tsx View on Github external
Promise.reject(new Error('Failed!')),
    );
    const { getByText } = render(
      wrapInIntlProvider(
        wrapInRouter(, [
          {
            path: ERROR_COMPONENT_ROUTE(),
            render: ({ match }) => (
              <span>{`Error Component: ${match.params.code}`}</span>
            ),
          },
        ]),
      ),
    );

    await screen.findByText('Error Component: notFound');
    expect(report).toBeCalledWith(new Error('Failed!'));
  });
});
github openfun / marsha / src / frontend / components / TimedTextCreationForm / index.spec.tsx View on Github external
},
          ],
        ),
      ),
    );
    await screen.findByText('Add a language');

    const input = screen.getByRole('textbox');
    fireEvent.change(input!, { target: { value: 'French' } });
    fireEvent.keyDown(input!, { keyCode: 9, key: 'Tab' });
    fireEvent.click(screen.getByText('French'));

    const button = screen.getByRole('button', { name: /Upload the file/i });
    fireEvent.click(button);

    await screen.findByText('There was an error during track creation.');

    expect(report).toHaveBeenCalledWith(
      new Error('Failed to create a new TimedTextTrack with fr, st: 500.'),
    );
  });
});
github openfun / marsha / src / frontend / components / UploadForm / index.spec.tsx View on Github external
mockGetResource.mockResolvedValue(object);

    const { container } = render(
      wrapInIntlProvider(
        wrapInRouter(
          ,
          [
            {
              path: DASHBOARD_ROUTE(),
              render: () =&gt; <span>dashboard</span>,
            },
          ],
        ),
      ),
    );
    await screen.findByText('Create a new video');

    fireEvent.drop(container.querySelector('input[type="file"]')!, {
      target: {
        files: [new File(['(⌐□_□)'], 'course.mp4', { type: 'video/mp4' })],
      },
    });
    await waitFor(() =&gt;
      expect(
        fetchMock.called('/api/videos/video-id/initiate-upload/', {
          method: 'POST',
        }),
      ).toBe(true),
    );
    await waitFor(() =&gt;
      expect(fetchMock.called('/api/videos/video-id/', { method: 'PUT' })).toBe(
        true,