|
1 |
| -/* eslint-disable max-nested-callbacks, react/prefer-stateless-function, class-methods-use-this, no-console */ |
| 1 | +/* eslint-disable max-nested-callbacks, react/prefer-stateless-function, class-methods-use-this, no-console, no-unused-expressions */ |
2 | 2 |
|
3 | 3 | import chai, {
|
4 | 4 | expect
|
@@ -239,6 +239,76 @@ describe('linkClass', () => {
|
239 | 239 | });
|
240 | 240 | });
|
241 | 241 |
|
| 242 | + context('can\'t write to properties', () => { |
| 243 | + context('when the element is frozen', () => { |
| 244 | + it('adds className but is still frozen', () => { |
| 245 | + let subject; |
| 246 | + |
| 247 | + subject = <div styleName='foo' />; |
| 248 | + |
| 249 | + Object.freeze(subject); |
| 250 | + subject = linkClass(subject, { |
| 251 | + foo: 'foo-1' |
| 252 | + }); |
| 253 | + |
| 254 | + expect(subject).to.be.frozen; |
| 255 | + expect(subject.props.className).to.equal('foo-1'); |
| 256 | + }); |
| 257 | + }); |
| 258 | + context('when the element\'s props are frozen', () => { |
| 259 | + it('adds className and only props are still frozen', () => { |
| 260 | + let subject; |
| 261 | + |
| 262 | + subject = <div styleName='foo' />; |
| 263 | + |
| 264 | + Object.freeze(subject.props); |
| 265 | + subject = linkClass(subject, { |
| 266 | + foo: 'foo-1' |
| 267 | + }); |
| 268 | + |
| 269 | + expect(subject.props).to.be.frozen; |
| 270 | + expect(subject.props.className).to.equal('foo-1'); |
| 271 | + }); |
| 272 | + }); |
| 273 | + context('when the element\'s props are not extensible', () => { |
| 274 | + it('adds className and props are still not extensible', () => { |
| 275 | + let subject; |
| 276 | + |
| 277 | + subject = <div styleName='foo' />; |
| 278 | + |
| 279 | + Object.preventExtensions(subject.props); |
| 280 | + subject = linkClass(subject, { |
| 281 | + foo: 'foo-1' |
| 282 | + }); |
| 283 | + |
| 284 | + expect(subject.props).to.not.be.extensible; |
| 285 | + expect(subject.props.className).to.equal('foo-1'); |
| 286 | + }); |
| 287 | + }); |
| 288 | + }); |
| 289 | + |
| 290 | + context('when element is an array', () => { |
| 291 | + it('handles each element individually', () => { |
| 292 | + let subject; |
| 293 | + |
| 294 | + subject = [ |
| 295 | + <div key={1} styleName='foo' />, |
| 296 | + <div key={2}> |
| 297 | + <p styleName='bar' /> |
| 298 | + </div> |
| 299 | + ]; |
| 300 | + |
| 301 | + subject = linkClass(subject, { |
| 302 | + bar: 'bar-1', |
| 303 | + foo: 'foo-1' |
| 304 | + }); |
| 305 | + |
| 306 | + expect(subject).to.be.an('array'); |
| 307 | + expect(subject[0].props.className).to.equal('foo-1'); |
| 308 | + expect(subject[1].props.children.props.className).to.equal('bar-1'); |
| 309 | + }); |
| 310 | + }); |
| 311 | + |
242 | 312 | describe('options.allowMultiple', () => {
|
243 | 313 | context('when multiple module names are used', () => {
|
244 | 314 | context('when false', () => {
|
|
0 commit comments