Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Button] Save some bytes on the production build #4346

Merged
merged 1 commit into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/FlatButton/FlatButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import EnhancedButton from '../internal/EnhancedButton';
import FlatButtonLabel from './FlatButtonLabel';

function validateLabel(props, propName, componentName) {
if (!props.children && !props.label && !props.icon) {
return new Error(`Required prop label or children or icon was not specified in ${componentName}.`);
if (process.env.NODE_ENV !== 'production') {
if (!props.children && !props.label && !props.icon) {
return new Error(`Required prop label or children or icon was not specified in ${componentName}.`);
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/FlatButton/FlatButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import {stub} from 'sinon';
import FlatButton from './FlatButton';
import getMuiTheme from '../styles/getMuiTheme';
import ActionAndroid from '../svg-icons/action/android';
Expand Down Expand Up @@ -148,4 +149,34 @@ describe('<FlatButton />', () => {
assert.strictEqual(wrapper.node.props.focusRippleColor, 'yellow', 'should be yellow');
assert.strictEqual(wrapper.node.props.touchRippleColor, 'yellow', 'should be yellow');
});

describe('propTypes', () => {
let consoleStub;

beforeEach(() => {
consoleStub = stub(console, 'error');
});

afterEach(() => {
console.error.restore(); // eslint-disable-line no-console
});

it('should throw when using wrong properties', () => {
shallowWithContext(
<FlatButton />
);
assert.strictEqual(consoleStub.callCount, 1);
assert.strictEqual(
consoleStub.args[0][0],
'Warning: Failed propType: Required prop label or children or icon was not specified in FlatButton.'
);
});

it('should not throw when using a valid properties', () => {
shallowWithContext(
<FlatButton label={0} />
);
assert.strictEqual(consoleStub.callCount, 0);
});
});
});
6 changes: 4 additions & 2 deletions src/RaisedButton/RaisedButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import EnhancedButton from '../internal/EnhancedButton';
import Paper from '../Paper';

function validateLabel(props, propName, componentName) {
if (!props.children && !props.label && !props.icon) {
return new Error(`Required prop label or children or icon was not specified in ${componentName}.`);
if (process.env.NODE_ENV !== 'production') {
if (!props.children && !props.label && !props.icon) {
return new Error(`Required prop label or children or icon was not specified in ${componentName}.`);
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/RaisedButton/RaisedButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import {mount, shallow} from 'enzyme';
import {stub} from 'sinon';
import {assert} from 'chai';
import RaisedButton from './RaisedButton';
import ActionAndroid from '../svg-icons/action/android';
Expand Down Expand Up @@ -102,4 +103,34 @@ describe('<RaisedButton />', () => {
muiTheme.raisedButton.fontSize
);
});

describe('propTypes', () => {
let consoleStub;

beforeEach(() => {
consoleStub = stub(console, 'error');
});

afterEach(() => {
console.error.restore(); // eslint-disable-line no-console
});

it('should throw when using wrong properties', () => {
shallowWithContext(
<RaisedButton />
);
assert.strictEqual(consoleStub.callCount, 1);
assert.strictEqual(
consoleStub.args[0][0],
'Warning: Failed propType: Required prop label or children or icon was not specified in RaisedButton.'
);
});

it('should not throw when using a valid properties', () => {
shallowWithContext(
<RaisedButton label={0} />
);
assert.strictEqual(consoleStub.callCount, 0);
});
});
});