测试React组件:Jest遇到意外令牌 [英] Testing react components: Jest encountered an unexpected token

查看:132
本文介绍了测试React组件:Jest遇到意外令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对Jest进行测试,但出现错误: 开玩笑遇到了意外的令牌 这通常意味着您正在尝试导入Jest无法解析的文件,例如这不是普通的JavaScript.

I am trying to test with Jest, but got an error: Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

我有一个照相馆应用程序,每当我单击图像时,都会弹出带有图像的模态.我想测试一下,当我单击图像时,弹出窗口是否显示或存在.有没有办法解决这个问题?

I have a photo gallery app and whenever I click on an image, a modal pops up with an image. I want to test that when I click on the image, the popup shows or exists. Is there a way to factor this?

这是我的代码:

import { shallow, mount, render } from 'enzyme';
import App from '../client/src/components/App';

describe('<PhotoItem />', () => {
  it('should popup image on click', () => {
    const wrapper = shallow(
      <App title="mock" />
    );
    wrapper.find('.item item-0').simulate('click');
    expect('.modal-opactiy').toExist();
  });

这里是我的package.json: "jest": { "verbose": true, "transformIgnorePatterns": ["/node_modules/(?!App)"], "testURL": "http://localhost/photos" }

HERE is my package.json: "jest": { "verbose": true, "transformIgnorePatterns": ["/node_modules/(?!App)"], "testURL": "http://localhost/photos" }

推荐答案

这里是相同的问题:您需要添加一个.babelrc文件,其内容如下:

You need to add a .babelrc file with:

{ "presets": ["env","react"] }

这篇关于测试React组件:Jest遇到意外令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆