Skip to content

Commit 3c1e285

Browse files
committed
fix lint and test errors
1 parent c072c02 commit 3c1e285

File tree

6 files changed

+37
-14
lines changed

6 files changed

+37
-14
lines changed

__mocks__/react-dom.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// this is here to avoid duplicate react entries in the examples
2+
// (one from the example's node_modules and one from the root's node_modules)
3+
module.exports = require('react-dom')

__mocks__/react-native.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// this is here to avoid duplicate react entries in the examples
2+
// (one from the example's node_modules and one from the root's node_modules)
3+
module.exports = require('react-native')

__tests__/Clock.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { StrictMode } from 'react'
2+
import { act } from 'react-dom/test-utils'
23
import { render, cleanup, flushEffects } from 'react-testing-library'
34
import sinon from 'sinon'
45
import App from '../examples/clock/src/App'
@@ -24,10 +25,14 @@ describe('Clock App', () => {
2425
test('should update to display the current time every second', () => {
2526
expect(container).toHaveTextContent('12:00:00 AM')
2627

27-
clock.tick(2000)
28+
act(() => {
29+
clock.tick(2000)
30+
})
2831
expect(container).toHaveTextContent('12:00:02 AM')
2932

30-
clock.tick(8500)
33+
act(() => {
34+
clock.tick(8500)
35+
})
3136
expect(container).toHaveTextContent('12:00:10 AM')
3237
})
3338

__tests__/router.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react'
2+
import { act } from 'react-dom/test-utils'
23
import { render, cleanup, fireEvent } from 'react-testing-library'
34
import { view, store } from 'react-easy-state'
45
import {
@@ -25,7 +26,9 @@ describe('withRouter interaction', () => {
2526
</Router>
2627
)
2728
expect(container).toHaveTextContent('0')
28-
counter.num++
29+
act(() => {
30+
counter.num++
31+
})
2932
expect(container).toHaveTextContent('1')
3033
})
3134

@@ -70,7 +73,9 @@ describe('withRouter interaction', () => {
7073
</Router>
7174
)
7275
expect(container).toHaveTextContent('0')
73-
counter.num++
76+
act(() => {
77+
counter.num++
78+
})
7479
expect(container).toHaveTextContent('1')
7580
})
7681

__tests__/styled.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react'
2+
import { act } from 'react-dom/test-utils'
23
import { render, cleanup } from 'react-testing-library'
34
import { view, store } from 'react-easy-state'
45
import { withTheme, ThemeProvider } from 'styled-components'
@@ -24,7 +25,9 @@ describe('withRouter interaction', () => {
2425
</Theme>
2526
)
2627
expect(container).toHaveTextContent('0')
27-
counter.num++
28+
act(() => {
29+
counter.num++
30+
})
2831
expect(container).toHaveTextContent('1')
2932
})
3033

@@ -61,7 +64,9 @@ describe('withRouter interaction', () => {
6164
</Theme>
6265
)
6366
expect(container).toHaveTextContent('0')
64-
counter.num++
67+
act(() => {
68+
counter.num++
69+
})
6570
expect(container).toHaveTextContent('1')
6671
})
6772

src/view.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { hasHooks } from './utils'
55
export let isInsideFunctionComponent = false
66
const COMPONENT = Symbol('owner component')
77

8-
export default function view(Comp) {
8+
export default function view (Comp) {
99
const isStatelessComp = !(Comp.prototype && Comp.prototype.isReactComponent)
1010

1111
let ReactiveComp
@@ -47,7 +47,7 @@ export default function view(Comp) {
4747
// a HOC which overwrites render, shouldComponentUpdate and componentWillUnmount
4848
// it decides when to run the new reactive methods and when to proxy to the original methods
4949
class ReactiveClassComp extends BaseComp {
50-
constructor(props, context) {
50+
constructor (props, context) {
5151
super(props, context)
5252

5353
this.state = this.state || {}
@@ -60,12 +60,14 @@ export default function view(Comp) {
6060
})
6161
}
6262

63-
render() {
64-
return isStatelessComp ? Comp(this.props, this.context) : super.render()
63+
render () {
64+
return isStatelessComp
65+
? Comp(this.props, this.context)
66+
: super.render()
6567
}
6668

6769
// react should trigger updates on prop changes, while easyState handles store changes
68-
shouldComponentUpdate(nextProps, nextState) {
70+
shouldComponentUpdate (nextProps, nextState) {
6971
const { props, state } = this
7072

7173
// respect the case when the user defines a shouldComponentUpdate
@@ -88,7 +90,7 @@ export default function view(Comp) {
8890
}
8991

9092
// add a custom deriveStoresFromProps lifecyle method
91-
static getDerivedStateFromProps(props, state) {
93+
static getDerivedStateFromProps (props, state) {
9294
if (super.deriveStoresFromProps) {
9395
// inject all local stores and let the user mutate them directly
9496
const stores = mapStateToStores(state)
@@ -101,7 +103,7 @@ export default function view(Comp) {
101103
return null
102104
}
103105

104-
componentWillUnmount() {
106+
componentWillUnmount () {
105107
// call user defined componentWillUnmount
106108
if (super.componentWillUnmount) {
107109
super.componentWillUnmount()
@@ -126,7 +128,7 @@ export default function view(Comp) {
126128
return ReactiveComp
127129
}
128130

129-
function mapStateToStores(state) {
131+
function mapStateToStores (state) {
130132
// find store properties and map them to their none observable raw value
131133
// to do not trigger none static this.setState calls
132134
// from the static getDerivedStateFromProps lifecycle method

0 commit comments

Comments
 (0)