Skip to content

Commit

Permalink
fix: change expect getBy toThrow pattern to queryBy not.toBeInDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Dec 28, 2023
1 parent fdc74c7 commit e9893dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/taxonomy/taxonomy-card/TaxonomyCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('<TaxonomyCard />', async () => {
});

it('not show the system-defined badge with normal taxonomies', () => {
const { getByText } = render(<TaxonomyCardComponent original={data} />);
expect(() => getByText('System-level')).toThrow();
const { queryByText } = render(<TaxonomyCardComponent original={data} />);
expect(queryByText('System-level')).not.toBeInTheDocument();
});

it('shows the system-defined badge with system taxonomies', () => {
Expand All @@ -78,8 +78,8 @@ describe('<TaxonomyCard />', async () => {
});

it('not show org count with taxonomies without orgs', () => {
const { getByText } = render(<TaxonomyCardComponent original={data} />);
expect(() => getByText('Assigned to 0 orgs')).toThrow();
const { queryByText } = render(<TaxonomyCardComponent original={data} />);
expect(queryByText('Assigned to 0 orgs')).not.toBeInTheDocument();
});

it('shows org count with taxonomies with orgs', () => {
Expand Down
36 changes: 18 additions & 18 deletions src/taxonomy/taxonomy-menu/TaxonomyMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ describe('<TaxonomyMenu />', async () => {

[true, false].forEach((iconMenu) => {
test('should open and close menu on button click', () => {
const { getByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);
const { getByTestId, queryByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);

// Menu closed/doesn't exist yet
expect(() => getByTestId('taxonomy-menu')).toThrow();
expect(queryByTestId('taxonomy-menu')).not.toBeInTheDocument();

// Click on the menu button to open
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -116,10 +116,10 @@ describe('<TaxonomyMenu />', async () => {
});

test('doesnt show systemDefined taxonomies disabled menus', () => {
const { getByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} systemDefined />);
const { getByTestId, queryByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} systemDefined />);

// Menu closed/doesn't exist yet
expect(() => getByTestId('taxonomy-menu')).toThrow();
expect(queryByTestId('taxonomy-menu')).not.toBeInTheDocument();

// Click on the menu button to open
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -128,14 +128,14 @@ describe('<TaxonomyMenu />', async () => {
expect(getByTestId('taxonomy-menu')).toBeVisible();

// Check that the import menu is not show
expect(() => getByTestId('taxonomy-menu-import')).toThrow();
expect(queryByTestId('taxonomy-menu-import')).not.toBeInTheDocument();
});

test('doesnt show freeText taxonomies disabled menus', () => {
const { getByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} allowFreeText />);
const { getByTestId, queryByTestId } = render(<TaxonomyMenuComponent iconMenu={iconMenu} allowFreeText />);

// Menu closed/doesn't exist yet
expect(() => getByTestId('taxonomy-menu')).toThrow();
expect(queryByTestId('taxonomy-menu')).not.toBeInTheDocument();

// Click on the menu button to open
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -144,14 +144,14 @@ describe('<TaxonomyMenu />', async () => {
expect(getByTestId('taxonomy-menu')).toBeVisible();

// Check that the import menu is not show
expect(() => getByTestId('taxonomy-menu-import')).toThrow();
expect(queryByTestId('taxonomy-menu-import')).not.toBeInTheDocument();
});

test('should open export modal on export menu click', () => {
const { getByTestId, getByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);
const { getByTestId, getByText, queryByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);

// Modal closed
expect(() => getByText('Select format to export')).toThrow();
expect(queryByText('Select format to export')).not.toBeInTheDocument();

// Click on export menu
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -164,7 +164,7 @@ describe('<TaxonomyMenu />', async () => {
fireEvent.click(getByText('Cancel'));

// Modal closed
expect(() => getByText('Select format to export')).toThrow();
expect(queryByText('Select format to export')).not.toBeInTheDocument();
});

test('should call import tags when menu click', () => {
Expand All @@ -178,7 +178,7 @@ describe('<TaxonomyMenu />', async () => {
});

test('should export a taxonomy', () => {
const { getByTestId, getByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);
const { getByTestId, getByText, queryByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);

// Click on export menu
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -189,15 +189,15 @@ describe('<TaxonomyMenu />', async () => {
fireEvent.click(getByTestId('export-button-1'));

// Modal closed
expect(() => getByText('Select format to export')).toThrow();
expect(queryByText('Select format to export')).not.toBeInTheDocument();
expect(getTaxonomyExportFile).toHaveBeenCalledWith(taxonomyId, 'json');
});

test('should open delete dialog on delete menu click', () => {
const { getByTestId, getByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);
const { getByTestId, getByText, queryByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);

// Modal closed
expect(() => getByText(`Delete "${taxonomyName}"`)).toThrow();
expect(queryByText(`Delete "${taxonomyName}"`)).not.toBeInTheDocument();

// Click on delete menu
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -210,11 +210,11 @@ describe('<TaxonomyMenu />', async () => {
fireEvent.click(getByText('Cancel'));

// Modal closed
expect(() => getByText(`Delete "${taxonomyName}"`)).toThrow();
expect(queryByText(`Delete "${taxonomyName}"`)).not.toBeInTheDocument();
});

test('should delete a taxonomy', async () => {
const { getByTestId, getByText, getByLabelText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);
const { getByTestId, getByLabelText, queryByText } = render(<TaxonomyMenuComponent iconMenu={iconMenu} />);

// Click on delete menu
fireEvent.click(getByTestId('taxonomy-menu-button'));
Expand All @@ -238,7 +238,7 @@ describe('<TaxonomyMenu />', async () => {
fireEvent.click(deleteButton);

// Modal closed
expect(() => getByText(`Delete "${taxonomyName}"`)).toThrow();
expect(queryByText(`Delete "${taxonomyName}"`)).not.toBeInTheDocument();

await waitFor(async () => {
expect(deleteTaxonomy).toBeCalledTimes(1);
Expand Down

0 comments on commit e9893dc

Please sign in to comment.