小编Jos*_*vin的帖子

火灾事件后反应测试库没有清理

我们一直在使用 React 钩子useReduceruseContext在我们的React应用程序中处理全局存储。

在使用 react 测试库运行测试时,我们注意到一旦我们的状态在一个测试中发生变化,接下来的所有测试现在都会发生该状态变化。

我们曾尝试进行清理,afterEach(cleanup)但没有奏效。

不知道发生了什么?

import React, { useContext, useReducer } from 'react'
import { render, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import TodosList from './TodosList'
import reducer from '../../reducers/reducer'
import Store from '../../context'
import fixture from '../../tests/fixtures'

function Component() {
  const [state, dispatch] = useReducer(reducer, fixture)

  return (
    <Store.Provider value={{ state, dispatch }}>
      <TodosList />
    </Store.Provider>
  )
}

describe('todos', () => {
  it('removes a todo when button is pressed', () …
Run Code Online (Sandbox Code Playgroud)

reactjs react-testing-library

5
推荐指数
1
解决办法
2074
查看次数

标签 统计

react-testing-library ×1

reactjs ×1