Skip to content

Commit 34a8728

Browse files
authored
Merge pull request gajus#148 from olistic/fix-unknown-prop-warning
Delete styleName prop after adding the corresponding className
2 parents 5ce0de5 + c29c8b4 commit 34a8728

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/linkClass.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
4545
}
4646

4747
elementShallowCopy.props.className = appendClassName;
48-
elementShallowCopy.props.styleName = null;
4948
}
5049
}
5150

51+
delete elementShallowCopy.props.styleName;
52+
5253
if (elementIsFrozen) {
5354
Object.freeze(elementShallowCopy.props);
5455
Object.freeze(elementShallowCopy);

tests/linkClass.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('linkClass', () => {
9898
expect(subject.props.children[0].props.className).to.equal('foo-1');
9999
expect(subject.props.children[1].props.className).to.equal('bar-1');
100100
});
101-
it('styleName is reset to null', () => {
101+
it('styleName is deleted from props', () => {
102102
let subject;
103103

104104
subject = <div>
@@ -111,8 +111,8 @@ describe('linkClass', () => {
111111
foo: 'foo-1'
112112
});
113113

114-
expect(subject.props.children[0].props.styleName).to.equal(null);
115-
expect(subject.props.children[1].props.styleName).to.equal(null);
114+
expect(subject.props.children[0].props).not.to.have.property('styleName');
115+
expect(subject.props.children[1].props).not.to.have.property('styleName');
116116
});
117117
});
118118
context('when multiple descendants have styleName and are iterable', () => {
@@ -261,7 +261,7 @@ describe('linkClass', () => {
261261
});
262262
});
263263

264-
it('unsets styleName property of the target element', () => {
264+
it('deletes styleName property from the target element', () => {
265265
let subject;
266266

267267
subject = <div styleName='foo'></div>;
@@ -271,10 +271,10 @@ describe('linkClass', () => {
271271
});
272272

273273
expect(subject.props.className).to.deep.equal('foo-1');
274-
expect(subject.props.styleName).to.deep.equal(null);
274+
expect(subject.props).not.to.have.property('styleName');
275275
});
276276

277-
it('unsets styleName property of the target element (deep)', () => {
277+
it('deletes styleName property from the target element (deep)', () => {
278278
let subject;
279279

280280
subject = <div styleName='foo'>
@@ -288,6 +288,6 @@ describe('linkClass', () => {
288288
});
289289

290290
expect(subject.props.children[0].props.className).to.deep.equal('bar-1');
291-
expect(subject.props.children[0].props.styleName).to.deep.equal(null);
291+
expect(subject.props.children[0].props).not.to.have.property('styleName');
292292
});
293293
});

tests/reactCssModules.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ describe('reactCssModules', () => {
3737
});
3838
context('a ReactComponent renders an element with the styleName prop', () => {
3939
context('the component is a class that extends React.Component', () => {
40-
it('that element should contain the equivalent className', () => {
41-
let Foo;
40+
let Foo,
41+
component;
4242

43+
beforeEach(() => {
4344
const shallowRenderer = TestUtils.createRenderer();
4445

4546
Foo = class extends React.Component {
@@ -54,15 +55,20 @@ describe('reactCssModules', () => {
5455

5556
shallowRenderer.render(<Foo />);
5657

57-
const component = shallowRenderer.getRenderOutput();
58-
58+
component = shallowRenderer.getRenderOutput();
59+
});
60+
it('that element should contain the equivalent className', () => {
5961
expect(component.props.className).to.equal('foo-1');
6062
});
63+
it('the styleName prop should be "consumed" in the process', () => {
64+
expect(component.props).not.to.have.property('styleName');
65+
});
6166
});
6267
context('the component is a stateless function component', () => {
63-
it('that element should contain the equivalent className', () => {
64-
let Foo;
68+
let Foo,
69+
component;
6570

71+
beforeEach(() => {
6672
const shallowRenderer = TestUtils.createRenderer();
6773

6874
Foo = () => {
@@ -75,10 +81,14 @@ describe('reactCssModules', () => {
7581

7682
shallowRenderer.render(<Foo />);
7783

78-
const component = shallowRenderer.getRenderOutput();
79-
84+
component = shallowRenderer.getRenderOutput();
85+
});
86+
it('that element should contain the equivalent className', () => {
8087
expect(component.props.className).to.equal('foo-1');
8188
});
89+
it('the styleName prop should be "consumed" in the process', () => {
90+
expect(component.props).not.to.have.property('styleName');
91+
});
8292
});
8393
});
8494
context('a ReactComponent renders nothing', () => {

0 commit comments

Comments
 (0)