Skip to content

Commit

Permalink
Support React.Suspense in snapshots. (#8180)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthovestadt authored and SimenB committed Mar 20, 2019
1 parent 5b680db commit 921edc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- `[jest-snapshot]` Improve report when matcher fails, part 14 ([#8132](https://github.com/facebook/jest/pull/8132))
- `[@jest/reporter]` Display todo and skip test descriptions when verbose is true ([#8038](https://github.com/facebook/jest/pull/8038))
- `[jest-runner]` Support default exports for test environments ([#8163](https://github.com/facebook/jest/pull/8163))
- `[pretty-format]` Support React.Suspense ([#8180](https://github.com/facebook/jest/pull/8180))

### Fixes

Expand Down
13 changes: 13 additions & 0 deletions packages/pretty-format/src/__tests__/react.test.tsx
Expand Up @@ -13,6 +13,7 @@ import {OptionsReceived} from '../types';

const elementSymbol = Symbol.for('react.element');
const fragmentSymbol = Symbol.for('react.fragment');
const suspenseSymbol = Symbol.for('react.suspense');
const testSymbol = Symbol.for('react.test.json');
const {ReactElement, ReactTestComponent} = prettyFormat.plugins;

Expand Down Expand Up @@ -308,6 +309,18 @@ test('supports a fragment with element child', () => {
).toEqual('<React.Fragment>\n <div>\n test\n </div>\n</React.Fragment>');
});

test('supports suspense', () => {
expect(
formatElement({
$$typeof: elementSymbol,
props: {
children: React.createElement('div', null, 'test'),
},
type: suspenseSymbol,
}),
).toEqual('<React.Suspense>\n <div>\n test\n </div>\n</React.Suspense>');
});

test('supports a single element with React elements with a child', () => {
assertPrintedJSX(
React.createElement('Mouse', {
Expand Down
3 changes: 3 additions & 0 deletions packages/pretty-format/src/plugins/ReactElement.ts
Expand Up @@ -40,6 +40,9 @@ const getType = (element: any) => {
if (ReactIs.isFragment(element)) {
return 'React.Fragment';
}
if (ReactIs.isSuspense(element)) {
return 'React.Suspense';
}
if (typeof type === 'object' && type !== null) {
if (ReactIs.isContextProvider(element)) {
return 'Context.Provider';
Expand Down

0 comments on commit 921edc0

Please sign in to comment.