Skip to content

Commit

Permalink
refactor(test): update react-test-library==>@test-library/react
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 24, 2019
1 parent 39d2591 commit a97ffa0
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 392 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// allow specifying true explicitly for boolean props
"react/jsx-boolean-value": 0,
"react-hooks/rules-of-hooks": "error",
"react/no-did-update-set-state": 0
"react/no-did-update-set-state": 0,
"jsx-quotes":"off"
}
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},
setupFilesAfterEnv: [
require.resolve('jest-dom/extend-expect'),
require.resolve('react-testing-library/cleanup-after-each'),
require.resolve('@testing-library/react/cleanup-after-each'),
'./scripts/global.js'
],
coveragePathIgnorePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"pretty-format": "^24.0.0",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-testing-library": "^6.0.0",
"@testing-library/react": "^8.0.0",
"remark-parse": "^6.0.3",
"remark-stringify": "^6.0.4",
"semver-regex": "^2.0.0",
Expand Down
5 changes: 0 additions & 5 deletions packages/react/src/.eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/src/__tests__/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SchemaForm, {
connect,
createAsyncFormActions
} from '../index'
import { render } from 'react-testing-library'
import { render } from '@testing-library/react'

beforeEach(() => {
registerFormField('string', connect()(props => <div>{props.value}</div>))
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/__tests__/context.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SchemaForm, {
FormConsumer,
createFormActions
} from '../index'
import { render, fireEvent, act } from 'react-testing-library'
import { render, fireEvent, act } from '@testing-library/react'

beforeEach(() => {
registerFormField(
Expand Down
60 changes: 29 additions & 31 deletions packages/react/src/__tests__/destruct.spec.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import React, { Fragment } from 'react'
import SchemaForm, { Field, registerFormField, connect } from '../index'
import { toArr } from '@uform/utils'
import { render } from 'react-testing-library'

beforeEach(() => {
registerFormField('string', connect()(props => <div>{props.value}</div>))

registerFormField('array', props => {
const { value, mutators, renderField } = props
return (
<Fragment>
{toArr(value).map((item, index) => {
return (
<div data-testid='item' key={index}>
{renderField(index)}
</div>
)
})}
<button
type='button'
onClick={() => {
mutators.push()
}}
>
Add Field
</button>
</Fragment>
)
})
import { render } from '@testing-library/react'

registerFormField('string', connect()(props => <div>{props.value}</div>))

registerFormField('array', props => {
const { value, mutators, renderField } = props
return (
<Fragment>
{toArr(value).map((item, index) => {
return (
<div data-testid="item" key={index}>
{renderField(index)}
</div>
)
})}
<button
type="button"
onClick={() => {
mutators.push()
}}
>
Add Field
</button>
</Fragment>
)
})

test('destruct with initial values', async () => {
const TestComponent = () => {
return (
<SchemaForm initialValues={{ aa: 123, bb: 321 }}>
<Field type='string' name='[aa,bb]' />
<Field type="string" name="[aa,bb]" />
</SchemaForm>
)
}
Expand All @@ -49,9 +47,9 @@ test('destruct with initial values in array', async () => {
const TestComponent = () => {
return (
<SchemaForm initialValues={{ array: [{ aa: 123, bb: 321 }] }}>
<Field type='array' name='array'>
<Field type='object'>
<Field type='string' name='[aa,bb]' />
<Field type="array" name="array">
<Field type="object">
<Field type="string" name="[aa,bb]" />
</Field>
</Field>
</SchemaForm>
Expand Down
Loading

0 comments on commit a97ffa0

Please sign in to comment.