withProjects.spec.jsx 982 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import {Project} from 'fixtures/js-stubs/project';
  2. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import withProjects from 'sentry/utils/withProjects';
  5. describe('withProjects HoC', function () {
  6. beforeEach(() => {
  7. act(() => ProjectsStore.reset());
  8. });
  9. function Output({projects, loadingProjects}) {
  10. if (loadingProjects) {
  11. return <p>Loading</p>;
  12. }
  13. return (
  14. <p>
  15. {projects.map(project => (
  16. <span key={project.slug}>{project.slug}</span>
  17. ))}
  18. </p>
  19. );
  20. }
  21. it('works', async function () {
  22. const Container = withProjects(Output);
  23. render(<Container />);
  24. expect(await screen.findByText('Loading')).toBeInTheDocument();
  25. // Insert into projects store
  26. const project = Project();
  27. act(() => ProjectsStore.loadInitialData([project]));
  28. expect(await screen.findByText(project.slug)).toBeInTheDocument();
  29. });
  30. });