Skip to content

Commit

Permalink
test(jest): opt-in to shorter snapshot format (#4843)
Browse files Browse the repository at this point in the history
* test(jest): opt-in to shorter snapshot format

jestjs/jest#11654

...waiting for the release of jest

* remove usage of setImmediate (doesn't exist in browser)

* make sessionStorage mock writable

* update jest to latest

* final update & snapshot changes

* simplify lockfile

* Update src/lib/__tests__/InstantSearch-test.tsx

* simpler without fake timerz
  • Loading branch information
Haroenv authored Aug 31, 2021
1 parent 0e151a9 commit 9f1831c
Show file tree
Hide file tree
Showing 56 changed files with 1,945 additions and 1,590 deletions.
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ module.exports = {
globals: {
__DEV__: true,
},

snapshotFormat: {
printBasicPrototype: false,
},
// reporter for circleci
reporters: [
'default',
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
"@testing-library/preact": "1.0.2",
"@types/classnames": "^2.2.7",
"@types/enzyme": "^3.1.15",
"@types/jest": "^26.0.22",
"@types/jest-diff": "^24.3.0",
"@types/jest": "^27.0.1",
"@types/jsdom": "^16.2.13",
"@types/scriptjs": "^0.0.2",
"@types/storybook__addon-actions": "^3.4.2",
Expand All @@ -98,7 +97,7 @@
"algoliasearch": "4.10.3",
"algoliasearch-v3": "npm:[email protected]",
"babel-eslint": "10.0.3",
"babel-jest": "26.6.3",
"babel-jest": "27.1.0",
"babel-loader": "8.0.6",
"babel-plugin-inline-replace-variables": "1.3.1",
"babel-plugin-polyfill-es-shims": "0.0.7",
Expand All @@ -120,12 +119,12 @@
"eslint-plugin-react": "7.18.0",
"eslint-plugin-react-hooks": "2.3.0",
"instantsearch-e2e-tests": "algolia/instantsearch-e2e-tests#1.3.0",
"jest": "26.6.3",
"jest-diff": "26.6.2",
"jest-environment-jsdom": "26.6.2",
"jest": "27.1.0",
"jest-diff": "27.1.0",
"jest-environment-jsdom": "27.1.0",
"jest-environment-jsdom-global": "2.0.4",
"jest-junit": "12.2.0",
"jest-watch-typeahead": "0.6.2",
"jest-watch-typeahead": "0.6.4",
"jscodeshift": "0.7.0",
"jsdom-global": "3.0.2",
"places.js": "1.17.1",
Expand Down
4 changes: 2 additions & 2 deletions scripts/jest/matchers/toWarnDev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */

import jestDiff from 'jest-diff';
import { diff } from 'jest-diff';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand Down Expand Up @@ -56,7 +56,7 @@ const matcher: jest.ExpectExtendMap = {
Difference:
${jestDiff(expectedMessage, actualWarning)}`,
${diff(expectedMessage, actualWarning)}`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/index-es-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('instantsearch()', () => {

it('includes the helper functions', () => {
expect(Object.keys(instantsearch)).toMatchInlineSnapshot(`
Array [
[
"version",
"createInfiniteHitsSessionStorageCache",
"highlight",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('instantsearch()', () => {

it('includes the API and the helper functions', () => {
expect(Object.keys(instantsearch)).toMatchInlineSnapshot(`
Array [
[
"version",
"connectors",
"widgets",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ClearRefinements should render <ClearRefinements /> 1`] = `
Array [
[
<div
className="root"
>
Array [
[
<button
className="button"
dangerouslySetInnerHTML={
Object {
{
"__html": "",
}
}
Expand All @@ -22,15 +22,15 @@ Array [
`;

exports[`ClearRefinements should render <ClearRefinements /> with a specific class when no refinements 1`] = `
Array [
[
<div
className="root"
>
Array [
[
<button
className="button disabled"
dangerouslySetInnerHTML={
Object {
{
"__html": "",
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/components/Hits/__tests__/__snapshots__/Hits-test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Hits markup should render <Hits /> 1`] = `
Array [
[
<div
className="root"
>
<ol
className="list"
>
Array [
[
<li
className="item"
dangerouslySetInnerHTML={
Object {
{
"__html": "item",
}
}
/>,
]
Array [
[
<li
className="item"
dangerouslySetInnerHTML={
Object {
{
"__html": "item",
}
}
Expand All @@ -34,28 +34,28 @@ Array [
`;

exports[`Hits markup should render <Hits /> without highlight function 1`] = `
Array [
[
<div
className="root"
>
<ol
className="list"
>
Array [
[
<li
className="item"
dangerouslySetInnerHTML={
Object {
{
"__html": "<mark class=\\"ais-Highlight-highlighted\\">name 1</mark>",
}
}
/>,
]
Array [
[
<li
className="item"
dangerouslySetInnerHTML={
Object {
{
"__html": "<mark class=\\"ais-Highlight-highlighted\\">name 2</mark>",
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MenuSelect should render <MenuSelect /> with custom templates 1`] = `
Array [
[
<div
className="root"
>
Expand All @@ -10,33 +10,33 @@ Array [
onChange={[Function]}
value=""
>
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "defaultOption",
}
}
value=""
/>,
]
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "foo",
}
}
value="foo"
/>,
]
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "bar",
}
}
Expand All @@ -49,7 +49,7 @@ Array [
`;

exports[`MenuSelect should render <MenuSelect /> with items 1`] = `
Array [
[
<div
className="root"
>
Expand All @@ -58,33 +58,33 @@ Array [
onChange={[Function]}
value=""
>
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "See all",
}
}
value=""
/>,
]
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "foo ()",
}
}
value="foo"
/>,
]
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "bar ()",
}
}
Expand All @@ -97,7 +97,7 @@ Array [
`;

exports[`MenuSelect should render <MenuSelect /> with no items 1`] = `
Array [
[
<div
className="root noRefinementRoot"
>
Expand All @@ -106,11 +106,11 @@ Array [
onChange={[Function]}
value=""
>
Array [
[
<option
className="option"
dangerouslySetInnerHTML={
Object {
{
"__html": "See all",
}
}
Expand Down
Loading

0 comments on commit 9f1831c

Please sign in to comment.