withProjects.spec.jsx 940 B

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