Skip to content

Commit

Permalink
Reducing the snapshot output of EuiMark unit tests. (#5772)
Browse files Browse the repository at this point in the history
* Reducing the snapshot output of EuiMark unit tests.
* Refactoring EuiMark test for smaller output.
* Updating two snapshot tests.
* Adding Emotion matchers to config, consolidating test blocks.
  • Loading branch information
1Copenut authored Apr 8, 2022
1 parent f0c17ae commit 7aa5510
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 56 deletions.
4 changes: 3 additions & 1 deletion scripts/jest/setup/emotion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createSerializer } from "@emotion/jest";
import { createSerializer, matchers } from "@emotion/jest";

expect.extend(matchers);

module.exports = createSerializer({
classNameReplacer: (className) => className,
Expand Down
50 changes: 0 additions & 50 deletions src/components/mark/__snapshots__/mark.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,3 @@ exports[`EuiMark is rendered 1`] = `
Marked
</mark>
`;

exports[`EuiMark is rendered: renders with emotion styles 1`] = `
.css-b9vly9-euiMarkStyles-EuiMark {
background-color: rgba(0,119,204,0.1);
font-weight: 700;
color: #343741;
}
.css-b9vly9-euiMarkStyles-EuiMark:before,
.css-b9vly9-euiMarkStyles-EuiMark:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.css-b9vly9-euiMarkStyles-EuiMark:before {
content: ' [highlight start] ';
}
.css-b9vly9-euiMarkStyles-EuiMark:after {
content: ' [highlight end] ';
}
<mark
class="euiMark css-b9vly9-euiMarkStyles-EuiMark"
>
Marked
</mark>
`;

exports[`No screen reader helper text is rendered without CSS :before and :after text 1`] = `
.css-dtzpxu-euiMarkStyles-EuiMark {
background-color: rgba(0,119,204,0.1);
font-weight: 700;
color: #343741;
}
<mark
aria-label="aria-label"
class="euiMark testClass1 testClass2 css-dtzpxu-euiMarkStyles-EuiMark"
data-test-subj="test subject string"
>
Marked
</mark>
`;
16 changes: 11 additions & 5 deletions src/components/mark/mark.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ describe('EuiMark', () => {
render(<EuiMark {...requiredProps}>Marked</EuiMark>)
).toMatchSnapshot();
});
});

describe('No screen reader helper text', () => {
renderWithStyles(<EuiMark>Marked</EuiMark>);
test('is rendered without CSS :before', () => {
expect(
render(
<EuiMark hasScreenReaderHelpText={false} {...requiredProps}>
Marked
</EuiMark>
)
).not.toHaveStyleRule('content', "' [highlight start] '");
});

test('is rendered without CSS :before and :after text', () => {
test('is rendered without CSS :after', () => {
expect(
render(
<EuiMark hasScreenReaderHelpText={false} {...requiredProps}>
Marked
</EuiMark>
)
).toMatchSnapshot();
).not.toHaveStyleRule('content', "' [highlight end] '");
});
});

0 comments on commit 7aa5510

Please sign in to comment.