Skip to content

Commit

Permalink
test(staticprops): replace expected error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
norbertkovacs95 authored and rolandszoke committed Jan 28, 2021
1 parent 423d5e6 commit 9d3e1a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
23 changes: 16 additions & 7 deletions __tests__/staticProps.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ describe('static props', () => {
name: PropTypes.string.isRequired,
};

const ViewComp = view(MyCustomCompName);
const ViewComp = MyCustomCompName;

const errorSpy = jest
.spyOn(console, 'error')
.mockImplementation((message) =>
expect(message.indexOf('Failed prop type')).not.toBe(-1),
);
.mockImplementation((warning, prop, error) => {
expect(warning).toBe('Warning: Failed %s type: %s%s');
expect(prop).toBe('prop');
expect(error).toBe(
'The prop `name` is marked as required in `MyCustomCompName`, but its value is `undefined`.',
);
});
expect(1).toBe(1);
render(<ViewComp number="Bob" />);
expect(errorSpy).toHaveBeenCalled();
errorSpy.mockRestore();
Expand All @@ -75,9 +80,13 @@ describe('static props', () => {

const errorSpy = jest
.spyOn(console, 'error')
.mockImplementation((message) =>
expect(message.indexOf('Failed prop type')).not.toBe(-1),
);
.mockImplementation((warning, prop, error) => {
expect(warning).toBe('Warning: Failed %s type: %s%s');
expect(prop).toBe('prop');
expect(error).toBe(
'Invalid prop `number` of type `string` supplied to `MyCustomCompName`, expected `number`.',
);
});
render(<ViewComp number="Bob" />);
expect(errorSpy).toHaveBeenCalled();
errorSpy.mockRestore();
Expand Down
24 changes: 11 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
"no-hook-react-testing-library": "npm:[email protected]",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"react": "^16.12.0",
"react-dom": "^16.13.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-native": "^0.63.4",
"react-router-dom": "^5.2.0",
"react-test-renderer": "^17.0.1",
Expand Down

0 comments on commit 9d3e1a4

Please sign in to comment.