From 8b563d66aaeb42dd78955363b871d88657569a2e Mon Sep 17 00:00:00 2001 From: mattkrick Date: Fri, 29 Apr 2016 16:26:01 -0500 Subject: [PATCH 1/2] add multi-line support for addCSS --- .../react-look/modules/api/StyleContainer.js | 2 +- .../react-look/test/api/StyleContainer-test.js | 16 +++++++++++++++- packages/react-look/test/api/StyleSheet-test.js | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/react-look/modules/api/StyleContainer.js b/packages/react-look/modules/api/StyleContainer.js index 59b0b2a..e33c490 100644 --- a/packages/react-look/modules/api/StyleContainer.js +++ b/packages/react-look/modules/api/StyleContainer.js @@ -63,7 +63,7 @@ class StyleContainer { * @param {string} styles - as css string */ addStatic(styles) { - this._addAndEmit(this.statics, styles) + this._addAndEmit(this.statics, styles.replace(/\s/g, '')) } /** diff --git a/packages/react-look/test/api/StyleContainer-test.js b/packages/react-look/test/api/StyleContainer-test.js index 887ff7e..473b3f9 100644 --- a/packages/react-look/test/api/StyleContainer-test.js +++ b/packages/react-look/test/api/StyleContainer-test.js @@ -25,7 +25,21 @@ describe('Adding a static css string', () => { it('should add it to the statics set', () => { const css = '.h1 { color: red }' StyleContainer.addStatic(css) - expect(StyleContainer.statics.has(css)).to.eql(true) + expect(StyleContainer.statics.has('.h1{color:red}')).to.eql(true) + }) +}) + +describe('Adding a static css string with spaces and comments', () => { + it('should add it to the statics set', () => { + const css = ` + /*! + * Banner + */ + .h1 { + color: red; + }` + StyleContainer.addStatic(css) + expect(StyleContainer.statics.has(css.replace(/\s/g, ''))).to.eql(true) }) }) diff --git a/packages/react-look/test/api/StyleSheet-test.js b/packages/react-look/test/api/StyleSheet-test.js index ea5a400..85d9d56 100644 --- a/packages/react-look/test/api/StyleSheet-test.js +++ b/packages/react-look/test/api/StyleSheet-test.js @@ -50,13 +50,13 @@ describe('Generating global CSS', () => { it('should treat strings as static css', () => { const css = 'h1 { color: blue }' StyleSheet.addCSS(css) - expect(StyleContainer.statics.has(css)).to.eql(true) + expect(StyleContainer.statics.has('h1{color:blue}')).to.eql(true) }) it('toCSS should just call addCSS', () => { const css = 'h1 { color: blue }' StyleSheet.toCSS(css) - expect(StyleContainer.statics.has(css)).to.eql(true) + expect(StyleContainer.statics.has('h1{color:blue}')).to.eql(true) }) }) From e36febf307bbeebe25102cf56184573900497cb6 Mon Sep 17 00:00:00 2001 From: mattkrick Date: Sat, 30 Apr 2016 16:16:20 -0500 Subject: [PATCH 2/2] add multi-line support for addCSS --- packages/react-look/modules/api/StyleContainer.js | 2 +- packages/react-look/test/api/StyleContainer-test.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-look/modules/api/StyleContainer.js b/packages/react-look/modules/api/StyleContainer.js index e33c490..767817f 100644 --- a/packages/react-look/modules/api/StyleContainer.js +++ b/packages/react-look/modules/api/StyleContainer.js @@ -63,7 +63,7 @@ class StyleContainer { * @param {string} styles - as css string */ addStatic(styles) { - this._addAndEmit(this.statics, styles.replace(/\s/g, '')) + this._addAndEmit(this.statics, styles.replace(/\s+/g, '')) } /** diff --git a/packages/react-look/test/api/StyleContainer-test.js b/packages/react-look/test/api/StyleContainer-test.js index 473b3f9..9310b2a 100644 --- a/packages/react-look/test/api/StyleContainer-test.js +++ b/packages/react-look/test/api/StyleContainer-test.js @@ -36,10 +36,11 @@ describe('Adding a static css string with spaces and comments', () => { * Banner */ .h1 { - color: red; + color: red; + margin: 10px 10px 10px 10px; }` StyleContainer.addStatic(css) - expect(StyleContainer.statics.has(css.replace(/\s/g, ''))).to.eql(true) + expect(StyleContainer.statics.has(css.replace(/\s+/g, ''))).to.eql(true) }) })