Javascript TypeError:无法读取属性';改变';未定义的

Javascript TypeError:无法读取属性';改变';未定义的,javascript,reactjs,react-testing-library,Javascript,Reactjs,React Testing Library,为什么以下代码中会出现此错误?我已经从“react testing library”导入了“Simulate”,但错误表明“Simulate”是“undefined” import React from 'react'; import { render, Simulate } from 'react-testing-library'; import CommentFeed from './CommentFeed'; const createProps = props => ({ head

为什么以下代码中会出现此错误?我已经从“react testing library”导入了“Simulate”,但错误表明“Simulate”是“undefined”

import React from 'react';
import { render, Simulate } from 'react-testing-library';
import CommentFeed from './CommentFeed';

const createProps = props => ({
header: 'Comment Feed',
comments: [
   {
      author: 'Ian Wilson',
      text: 'A boats a boat but a mystery box could be anything.',
   },
   {
     author: 'Max Powers Jr',
     text: 'Krypton sucks.',
   },
  ],
  createComment: jest.fn(),
  ...props,
})

describe('CommentFeed', () => {
  const props = { header : 'Comment Feed', comments : []};

  /* ... */

  it('allows the user to add a comment', () => {
    // Arrange
    const newComment = { author: 'Socrates', text: 'Why?' };
    let props = createProps();
    const { container, getByLabelText } = render(<CommentFeed {...props} />);

    const authorNode = getByLabelText('Author');
    const textNode = getByLabelText('Comment');
    const formNode = container.querySelector('form');

   // Act
    authorNode.value = newComment.author;
    textNode.value = newComment.text;

    Simulate.change(authorNode); // Where the error occurs
    Simulate.change(textNode);

    Simulate.submit(formNode);

    // Assert
    expect(props.createComment).toHaveBeenCalledTimes(1);
    expect(props.createComment).toHaveBeenCalledWith(newComment);
  });
});
从“React”导入React;
从“反应测试库”导入{render,Simulate};
从“/CommentFeed”导入CommentFeed;
const createProps=props=>({
标题:“注释提要”,
评论:[
{
作者:《伊恩·威尔逊》,
文字:“一条船一条船,但一个神秘的盒子可以是任何东西。”,
},
{
作者:《小麦克斯·鲍尔斯》,
文字:“氪星太差劲了。”,
},
],
createComment:jest.fn(),
…道具,
})
描述('CommentFeed',()=>{
const props={header:'Comment Feed',comments:[]};
/* ... */
它('允许用户添加注释',()=>{
//安排
康斯特·纽科门={作者:“苏格拉底”,文本:“为什么?”;
让props=createProps();
const{container,getByLabelText}=render();
const authorNode=getByLabelText('Author');
const textNode=getByLabelText('Comment');
const formNode=container.querySelector('form');
//表演
authorNode.value=newComment.author;
textNode.value=newComment.text;
Simulate.change(authorNode);//错误发生的位置
Simulate.change(textNode);
模拟提交(formNode);
//断言
expect(props.createComment).tohavebeincalledtimes(1);
期望(props.createComment).toHaveBeenCalledWith(newComment);
});
});

我正在搜索此问题,但找不到有关“模拟”行为的任何信息

tryed var test=new Simulate()


然后进行测试等…

Simulate
已从react测试库中删除。您今天需要使用的是
fireEvent

您可以这样使用它:

import { fireEvent } from 'react-testing-library'

// Then in your test

fireEvent.change(authorNode, { target: { value: newComment.author } })

您可以在中阅读有关fireEvent的更多信息。

欢迎来到SO!我在GitHub页面上找不到任何关于
react测试库
Simulate
参考。你是从一个特定的例子开始工作的吗?是的。从这一个:什么是“这个错误”,在所有的代码中它发生在哪里?