diff --git a/.gitignore b/.gitignore index dd8ec196..3274b423 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ yarn.lock /dist_docs/ _book/ /storybook-static/ +yarn-error.log diff --git a/.npmignore b/.npmignore index e79e0549..98645ebc 100644 --- a/.npmignore +++ b/.npmignore @@ -21,3 +21,4 @@ _book/ /.storybook/ /docs/ /storybook-static/ +yarn-error.log diff --git a/package.json b/package.json index fc84fba6..832afe27 100644 --- a/package.json +++ b/package.json @@ -50,17 +50,16 @@ "@types/react": "^16.3.17", "@types/react-dom": "16.0.3", "chai": "4.1.2", - "enzyme": "3.3.0", + "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", - "enzyme-to-json": "3.3.0", + "enzyme-to-json": "^3.3.4", "gulp": "3.9.1", "gulp-typescript": "3", "jest": "22.1.2", "jest-environment-jsdom": "^22.1.4", "jest-environment-jsdom-global": "^1.0.3", - "jest-tap-reporter": "1.9.0", "mocha": "5.0.0", - "mol-conventional-changelog": "1.2.0", + "git-cz": "^1.7.0", "react-markdown": "3.1.4", "react-test-renderer": "16.2.0", "rimraf": "2.6.2", @@ -80,7 +79,7 @@ }, "config": { "commitizen": { - "path": "./node_modules/mol-conventional-changelog" + "path": "git-cz" } }, "jest": { @@ -98,9 +97,6 @@ "setupFiles": [ "./src/__tests__/setup.js" ], - "reporters": [ - "jest-tap-reporter" - ], "testEnvironment": "jest-environment-jsdom-global" }, "keywords": [ diff --git a/src/MediaSensor/index.ts b/src/MediaSensor/index.ts index 208e5631..a0292fc7 100644 --- a/src/MediaSensor/index.ts +++ b/src/MediaSensor/index.ts @@ -19,6 +19,7 @@ export interface IMediaSensorState { export class MediaSensor extends Component { mql: MediaQueryList; state: IMediaSensorState; + mounted = false; constructor (props, context) { super(props, context); @@ -35,6 +36,10 @@ export class MediaSensor extends Component } } + componentDidMount () { + this.mounted = true; + } + componentDidUpdate (props) { if (props.query !== this.props.query) { this.updateQuery(); @@ -42,10 +47,15 @@ export class MediaSensor extends Component } componentWillUnmount () { + this.mounted = false; this.removeListener(); } onMediaChange = (mediaQueryList) => { + if (!this.mounted) { + return; + } + this.setState({ matches: !!mediaQueryList.matches }); diff --git a/src/Slider/index.ts b/src/Slider/index.ts index 3285d047..a62f4ec1 100644 --- a/src/Slider/index.ts +++ b/src/Slider/index.ts @@ -80,7 +80,7 @@ export class Slider extends Component { }; startScrubbing () { - if (!this.state.isSliding) { + if (!this.state.isSliding && this.mounted) { (this.props.onScrubStart || noop)(); this.setState({isSliding: true}); this.bindEvents(); @@ -88,7 +88,7 @@ export class Slider extends Component { } stopScrubbing = () => { - if (this.state.isSliding) { + if (this.state.isSliding && this.mounted) { (this.props.onScrubStop || noop)(); this.setState({isSliding: false}); this.unbindEvents(); diff --git a/src/WidthQuery/__tests__/__snapshots__/index.test.tsx.snap b/src/WidthQuery/__tests__/__snapshots__/index.test.tsx.snap index 66d7bdbd..68e626b2 100644 --- a/src/WidthQuery/__tests__/__snapshots__/index.test.tsx.snap +++ b/src/WidthQuery/__tests__/__snapshots__/index.test.tsx.snap @@ -1,7 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` crashes if less than two children provided 1`] = `" expects multiple children."`; - exports[` picks the correct by maxWidth 1 1`] = ` renders first matching view 1`] = ` `; -exports[` renders with crashing, expects multiple children 1`] = `" expects multiple children."`; - exports[` treats empty maxWidth as Infinity 1`] = ` view 5 diff --git a/src/WidthQuery/__tests__/index.test.tsx b/src/WidthQuery/__tests__/index.test.tsx index 625076f7..42d41a78 100644 --- a/src/WidthQuery/__tests__/index.test.tsx +++ b/src/WidthQuery/__tests__/index.test.tsx @@ -6,22 +6,6 @@ import {WidthQuery} from '..'; import {View} from '../../View'; describe('', () => { - it('renders with crashing, expects multiple children', () => { - expect(() => { - render(, document.createElement('div')); - }).toThrowErrorMatchingSnapshot(); - }); - - it('crashes if less than two children provided', () => { - expect(() => { - const jsx = - view 1 - ; - - render(jsx, document.createElement('div')); - }).toThrowErrorMatchingSnapshot(); - }); - it('renders first matching view', () => { const jsx = view 1 diff --git a/src/context/__tests__/index.server.test.tsx b/src/context/__tests__/index.server.test.tsx new file mode 100644 index 00000000..9e581424 --- /dev/null +++ b/src/context/__tests__/index.server.test.tsx @@ -0,0 +1,56 @@ +/** + * @jest-environment node + */ + +import {createElement as h} from 'react'; +import {renderToStaticMarkup} from 'react-dom/server'; +import {Provider, Consumer} from '..'; + +describe(' SSR', () => { + it('renders without crashing with no value', () => { + const element = ( + + {(theme) => { + return
Color is: {theme.color}
; + }}
+
+ ); + const html = renderToStaticMarkup(element); + + expect(html).toBe('
Color is: red
'); + }); + + it(' passes context to ', () => { + const value = {foo: 'bar'}; + const jsx = h( + Provider, + {name: 'a', value}, + h(Consumer, {name: 'a'}, val => { + return h('div', {}, val.foo); + }) + ); + const html = renderToStaticMarkup(jsx); + + expect(html).toBe('
bar
'); + }); + + it('multiple contexts received by multiple s', () => { + const jsx = h( + Provider, + {name: 'a', value: {foo1: 'bar'}}, + h( + Provider, + {name: 'b', value: {foo2: 'bar2'}}, + h(Consumer, {name: 'b'}, val1 => { + return h(Consumer, {name: 'a'}, val2 => { + return h('div', {}, val1.foo2 + val2.foo1); + }); + }) + ) + ); + + const html = renderToStaticMarkup(jsx); + + expect(html).toBe('
bar2bar
'); + }); +}); diff --git a/src/context/__tests__/index.test-server.tsx b/src/context/__tests__/index.test-server.tsx deleted file mode 100644 index 0220cac6..00000000 --- a/src/context/__tests__/index.test-server.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import {createElement as h} from 'react'; -import {renderToStaticMarkup} from 'react-dom/server'; -import {expect} from 'chai'; -import {Provider, Consumer} from '..'; - -describe(' SSR', () => { - it('renders without crashing with no value', () => { - const element = ( - - {(theme) => { - return
Color is: {theme.color}
; - }}
-
- ); - const html = renderToStaticMarkup(element); - - expect(html).to.equal('
Color is: red
'); - }); -}); diff --git a/src/context/__tests__/index.test.ts b/src/context/__tests__/index.test.ts deleted file mode 100644 index 0fb65e66..00000000 --- a/src/context/__tests__/index.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import {createElement as h} from 'react'; -import {mount} from 'enzyme'; -import {Consumer, Provider} from '../index'; - -describe('context', () => { - it(' passes context to ', () => { - const value = {foo: 'bar'}; - const jsx = h( - Provider, - {name: 'a', value}, - h(Consumer, {name: 'a'}, val => { - return h('div', {}, val.foo); - }) - ); - const wrapper = mount(jsx); - - expect(wrapper.find('div').props().children).toBe('bar'); - }); - - it('multiple contexts received by multiple s', () => { - const jsx = h( - Provider, - {name: 'a', value: {foo1: 'bar'}}, - h( - Provider, - {name: 'b', value: {foo2: 'bar2'}}, - h(Consumer, {name: 'b'}, val1 => { - return h(Consumer, {name: 'a'}, val2 => { - return h('div', {}, val1.foo2 + val2.foo1); - }); - }) - ) - ); - - const wrapper = mount(jsx); - - expect(wrapper.find('div').props().children).toBe('bar2bar'); - }); - - it(' merges multiple values with the same name', () => { - const jsx = h( - Provider, - {name: 'theme', value: {color: '1', background: '2'}}, - h( - Provider, - {name: 'theme', value: {color: '2', size: '3'}}, - h( - Provider, - { - name: 'theme', - value: {color: '3', size: '4', hover: true}, - }, - h(Consumer, {name: 'theme'}, val => { - expect(val).toEqual({ - hover: true, - size: '4', - color: '3', - background: '2', - }); - return null; - }) - ) - ) - ); - mount(jsx); - }); -}); diff --git a/src/route/__tests__/index.server.test.tsx b/src/route/__tests__/index.server.test.tsx index 075fc27a..30924e17 100644 --- a/src/route/__tests__/index.server.test.tsx +++ b/src/route/__tests__/index.server.test.tsx @@ -1,5 +1,5 @@ /** - * @jest-environment jsdom + * @jest-environment node */ import {createElement as h} from 'react'; diff --git a/src/route/__tests__/index.test.tsx b/src/route/__tests__/index.test.tsx deleted file mode 100644 index d8afe0d9..00000000 --- a/src/route/__tests__/index.test.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import {mount} from 'enzyme'; -import {h} from '../../util'; -import {Router, Route} from '..'; - -describe('route', () => { - describe('', () => { - it('is a component', () => { - expect(Router).toBeInstanceOf(Function); - }); - }); - - describe('', () => { - it('is a component', () => { - expect(Route).toBeInstanceOf(Function); - }); - - it('does basic routing', () => { - const wrapper = mount( - -
- - /foo - - - /bar - -
-
- ); - - const html = wrapper.html(); - - expect(html.includes('
/foo')).toBe(true); - expect(html.includes('
/bar')).toBe(false); - }); - }); -}); diff --git a/src/theme/__tests__/index.test.ts b/src/theme/__tests__/index.server.test.ts similarity index 58% rename from src/theme/__tests__/index.test.ts rename to src/theme/__tests__/index.server.test.ts index d2dee322..5f339790 100644 --- a/src/theme/__tests__/index.test.ts +++ b/src/theme/__tests__/index.server.test.ts @@ -1,21 +1,24 @@ +/** + * @jest-environment node + */ + import {createElement as h} from 'react'; -import {mount} from 'enzyme'; +import {renderToStaticMarkup} from 'react-dom/server'; import {Theme, Themed, withTheme} from '../index'; -describe('themestyler', () => { +describe('theme', () => { describe('', () => { it(' passes theme to ', () => { - const wrapper = mount(h(Theme, {value: {color: 'red'}}, + const html = renderToStaticMarkup(h(Theme, {value: {color: 'red'}}, h('div', {}, h(Themed, {}, theme => { return h('span', {}, theme.color); }) ) )); - expect(wrapper.find('span').props().children).toBe('red'); - }); - xit('merges multiple themes together', () => {}); + expect(html).toMatch('red'); + }); }); describe('withTheme()', () => { @@ -24,9 +27,9 @@ describe('themestyler', () => { return h('div', {}, theme.color); }; const BoxThemed = withTheme(Box); - const wrapper = mount(h(Theme, {value: {color: 'red'}}, h(BoxThemed))); + const html = renderToStaticMarkup(h(Theme, {value: {color: 'red'}}, h(BoxThemed))); - console.log(wrapper.html()); + expect(html).toBe('
red
'); }); }); -}); \ No newline at end of file +});