From ac8d5d5c74bbc073d6d1f372ce15b8b2cffb3e52 Mon Sep 17 00:00:00 2001 From: Abhishek Jakhar Date: Mon, 19 Oct 2020 14:40:56 +0530 Subject: [PATCH] use getBy query instead of queryBy when asserting for elements present in document (#2951) * replace queryByText with getByText when asserting for presence of element * use string instead of regex for line numbers * cleanup test case of CodeSnippet --- .changeset/lovely-suits-flash.md | 5 +++++ .../CodeSnippet/CodeSnippet.test.tsx | 20 +++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 .changeset/lovely-suits-flash.md diff --git a/.changeset/lovely-suits-flash.md b/.changeset/lovely-suits-flash.md new file mode 100644 index 0000000000..f093290c85 --- /dev/null +++ b/.changeset/lovely-suits-flash.md @@ -0,0 +1,5 @@ +--- +'@backstage/core': patch +--- + +update the test cases of CodeSnippet component diff --git a/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx b/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx index 1a76f84f44..466abe6012 100644 --- a/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx +++ b/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx @@ -20,10 +20,10 @@ import { wrapInTestApp } from '@backstage/test-utils'; import { CodeSnippet } from './CodeSnippet'; -const JAVASCRIPT = `const greeting = "Hello"; -const world = "World"; - -const greet = person => gretting + " " + person + "!"; +const JAVASCRIPT = ` + const greeting = "Hello"; + const world = "World"; + const greet = person => gretting + " " + person + "!"; `; const minProps = { @@ -48,20 +48,20 @@ describe('', () => { }); it('renders with line numbers', () => { - const { queryByText } = render( + const { getByText } = render( wrapInTestApp(), ); - expect(queryByText(/1/)).toBeInTheDocument(); - expect(queryByText(/2/)).toBeInTheDocument(); - expect(queryByText(/3/)).toBeInTheDocument(); + expect(getByText('1')).toBeInTheDocument(); + expect(getByText('2')).toBeInTheDocument(); + expect(getByText('3')).toBeInTheDocument(); }); it('copy code using button', async () => { document.execCommand = jest.fn(); - const rendered = render( + const { getByTitle } = render( wrapInTestApp(), ); - const button = rendered.getByTitle('Text copied to clipboard'); + const button = getByTitle('Text copied to clipboard'); fireEvent.click(button); expect(document.execCommand).toHaveBeenCalled(); });