|
1 | | -/* eslint-disable max-nested-callbacks, react/prefer-stateless-function, class-methods-use-this */ |
| 1 | +/* eslint-disable max-nested-callbacks, react/prefer-stateless-function, class-methods-use-this, no-console */ |
2 | 2 |
|
3 | | -import { |
| 3 | +import chai, { |
4 | 4 | expect |
5 | 5 | } from 'chai'; |
| 6 | +import spies from 'chai-spies'; |
6 | 7 | import React from 'react'; |
7 | 8 | import TestUtils from 'react-addons-test-utils'; |
8 | 9 | import jsdom from 'jsdom'; |
9 | 10 | import linkClass from './../src/linkClass'; |
10 | 11 |
|
| 12 | +chai.use(spies); |
| 13 | + |
11 | 14 | describe('linkClass', () => { |
12 | 15 | context('ReactElement does not define styleName', () => { |
13 | 16 | it('does not affect element properties', () => { |
@@ -264,24 +267,37 @@ describe('linkClass', () => { |
264 | 267 | }); |
265 | 268 | }); |
266 | 269 |
|
267 | | - describe('options.errorWhenNotFound', () => { |
| 270 | + describe('options.handleNotFoundStyleName', () => { |
268 | 271 | context('when styleName does not match an existing CSS module', () => { |
269 | | - context('when false', () => { |
270 | | - it('ignores the missing CSS module', () => { |
271 | | - let subject; |
272 | | - |
273 | | - subject = <div styleName='foo' />; |
274 | | - |
275 | | - subject = linkClass(subject, {}, {errorWhenNotFound: false}); |
| 272 | + context('when throw', () => { |
| 273 | + it('throws an error', () => { |
| 274 | + expect(() => { |
| 275 | + linkClass(<div styleName='foo' />, {}, {handleNotFoundStyleName: 'throw'}); |
| 276 | + }).to.throw(Error, '"foo" CSS module is undefined.'); |
| 277 | + }); |
| 278 | + }); |
| 279 | + context('when log', () => { |
| 280 | + it('logs a warning to the console', () => { |
| 281 | + const warnSpy = chai.spy(() => {}); |
276 | 282 |
|
277 | | - expect(subject.props.className).to.be.an('undefined'); |
| 283 | + console.warn = warnSpy; |
| 284 | + linkClass(<div styleName='foo' />, {}, {handleNotFoundStyleName: 'log'}); |
| 285 | + expect(warnSpy).to.have.been.called(); |
278 | 286 | }); |
279 | 287 | }); |
280 | | - context('when is true', () => { |
281 | | - it('throws an error', () => { |
| 288 | + context('when ignore', () => { |
| 289 | + it('does not log a warning', () => { |
| 290 | + const warnSpy = chai.spy(() => {}); |
| 291 | + |
| 292 | + console.warn = warnSpy; |
| 293 | + linkClass(<div styleName='foo' />, {}, {handleNotFoundStyleName: 'ignore'}); |
| 294 | + expect(warnSpy).to.not.have.been.called(); |
| 295 | + }); |
| 296 | + |
| 297 | + it('does not throw an error', () => { |
282 | 298 | expect(() => { |
283 | | - linkClass(<div styleName='foo' />, {}, {errorWhenNotFound: true}); |
284 | | - }).to.throw(Error, '"foo" CSS module is undefined.'); |
| 299 | + linkClass(<div styleName='foo' />, {}, {handleNotFoundStyleName: 'ignore'}); |
| 300 | + }).to.not.throw(Error, '"foo" CSS module is undefined.'); |
285 | 301 | }); |
286 | 302 | }); |
287 | 303 | }); |
|
0 commit comments