Skip to content

Commit c29c8b4

Browse files
committed
Delete styleName prop after adding the corresponding className
React CSS Modules should "consume" the styleName property of a decorated Component as it is not intended for its children.
1 parent e1b4a3d commit c29c8b4

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
@@ -46,10 +46,11 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
4646
}
4747

4848
elementShallowCopy.props.className = appendClassName;
49-
elementShallowCopy.props.styleName = null;
5049
}
5150
}
5251

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

tests/linkClass.js

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

105105
subject = <div>
@@ -112,8 +112,8 @@ describe('linkClass', () => {
112112
foo: 'foo-1'
113113
});
114114

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

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

268268
subject = <div styleName='foo'></div>;
@@ -272,10 +272,10 @@ describe('linkClass', () => {
272272
});
273273

274274
expect(subject.props.className).to.deep.equal('foo-1');
275-
expect(subject.props.styleName).to.deep.equal(null);
275+
expect(subject.props).not.to.have.property('styleName');
276276
});
277277

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

281281
subject = <div styleName='foo'>
@@ -289,6 +289,6 @@ describe('linkClass', () => {
289289
});
290290

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

tests/reactCssModules.js

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

44+
beforeEach(() => {
4445
const shallowRenderer = TestUtils.createRenderer();
4546

4647
Foo = class extends React.Component {
@@ -55,15 +56,20 @@ describe('reactCssModules', () => {
5556

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

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

72+
beforeEach(() => {
6773
const shallowRenderer = TestUtils.createRenderer();
6874

6975
Foo = () => {
@@ -76,10 +82,14 @@ describe('reactCssModules', () => {
7682

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

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

0 commit comments

Comments
 (0)