Skip to content

Commit

Permalink
Fail test if it 'console.error's (#16116)
Browse files Browse the repository at this point in the history
* Fail test if it 'console.error's

* oneOf -> oneOfType

* Fix react-color console.error
  • Loading branch information
kimjoar authored Jan 18, 2018
1 parent 88ed489 commit 7b0b381
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/dev/jest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"setupFiles": [
"<rootDir>/src/dev/jest/setup/babel_polyfill.js",
"<rootDir>/src/dev/jest/setup/enzyme.js"
"<rootDir>/src/dev/jest/setup/enzyme.js",
"<rootDir>/src/dev/jest/setup/throw_on_console_error.js"
],
"coverageDirectory": "<rootDir>/target/jest-coverage",
"coverageReporters": [
Expand Down
5 changes: 5 additions & 0 deletions src/dev/jest/setup/throw_on_console_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Fail if a test ends up `console.error`-ing, e.g. if React logs because of a
// failed prop types check.
console.error = message => {
throw new Error(message);
};
7 changes: 7 additions & 0 deletions ui_framework/src/components/color_picker/color_picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ let onChange;

beforeEach(() => {
onChange = sinon.spy();

// There's a `console.error` within `react-color`, so we're just "hiding it"
sinon.stub(console, 'error');
});

afterEach(() => {
console.error.restore();
});

test('renders KuiColorPicker', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function KuiListingTable({

KuiListingTable.propTypes = {
header: PropTypes.arrayOf(
PropTypes.oneOf([
PropTypes.oneOfType([
PropTypes.node,
PropTypes.shape({
content: PropTypes.node,
Expand All @@ -141,7 +141,7 @@ KuiListingTable.propTypes = {
rows: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
cells: PropTypes.arrayOf(
PropTypes.oneOf([
PropTypes.oneOfType([
PropTypes.node,
PropTypes.shape({
content: PropTypes.node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ KuiListingTableRow.propTypes = {
row: PropTypes.shape({
id: PropTypes.string,
cells: PropTypes.arrayOf(
PropTypes.oneOf([
PropTypes.oneOfType([
PropTypes.node,
PropTypes.shape({
content: PropTypes.node,
Expand Down

0 comments on commit 7b0b381

Please sign in to comment.