Skip to content

Commit

Permalink
fix doc explorer tests by adding context provider
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheyenbrock committed May 11, 2022
1 parent 53e5813 commit f006a54
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/graphiql/src/components/__tests__/DocExplorer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@
*/
import React from 'react';
import { render } from '@testing-library/react';
import { DocExplorer } from '../DocExplorer';
import { ExplorerContextProvider } from '@graphiql/react';

import { DocExplorer } from '../DocExplorer';
import { ExampleSchema } from './ExampleSchema';

function DocExplorerWithContext(
props: React.ComponentProps<typeof DocExplorer>,
) {
return (
<ExplorerContextProvider>
<DocExplorer {...props} />
</ExplorerContextProvider>
);
}

describe('DocExplorer', () => {
it('renders spinner when no schema prop is present', () => {
const { container } = render(<DocExplorer />);
const { container } = render(<DocExplorerWithContext />);
const spinner = container.querySelectorAll('.spinner-container');
expect(spinner).toHaveLength(1);
});
it('renders with null schema', () => {
const { container } = render(<DocExplorer schema={null} />);
const { container } = render(<DocExplorerWithContext schema={null} />);
const error = container.querySelectorAll('.error-container');
expect(error).toHaveLength(1);
expect(error[0]).toHaveTextContent('No Schema Available');
});
it('renders with schema', () => {
const { container } = render(<DocExplorer schema={ExampleSchema} />);
const { container } = render(
<DocExplorerWithContext schema={ExampleSchema} />,
);
const error = container.querySelectorAll('.error-container');
expect(error).toHaveLength(0);
expect(container.querySelector('.doc-type-description')).toHaveTextContent(
Expand Down

0 comments on commit f006a54

Please sign in to comment.