Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
rickhanlonii committed Mar 16, 2018
commit 20d2bd25542097d410fa797dcd449732485e1351
8 changes: 8 additions & 0 deletions packages/pretty-format/src/__tests__/react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const React = require('react');
const renderer = require('react-test-renderer');

const elementSymbol = Symbol.for('react.element');
const fragmentSymbol = Symbol.for('react.fragment');
const testSymbol = Symbol.for('react.test.json');

const prettyFormat = require('..');
Expand Down Expand Up @@ -90,6 +91,13 @@ test('supports a single element with mixed children', () => {
);
});

test('supports a single fragment with one child', () => {
Copy link
Member Author

@rickhanlonii rickhanlonii Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails because we're on React 15:

Thoughts on updating?

Copy link
Member Author

@rickhanlonii rickhanlonii Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternatives are:

  • Don't support
  • Don't test
  • Unit test just getType
  • try/catch the React throw:
test('supports a single fragment with one child', () => {
  const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {});
  try {
    assertPrintedJSX(
      React.createElement(fragmentSymbol, null, 0),
      '<React.Fragment>\n  0\n</React.Fragment>',
    );
  } catch(e) {
    if (e.message.indexOf('Element type is invalid:') === 0) {
      return;
    }

    throw e;
  }
  spy.mockRestore();
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update to latest React

assertPrintedJSX(
React.createElement(fragmentSymbol, null, 0),
'<React.Fragment>\n 0\n</React.Fragment>',
);
});

test('supports props with strings', () => {
assertPrintedJSX(
React.createElement('Mouse', {style: 'color:red'}),
Expand Down