在react组件中需要txt文件会中断jest snapshot

时间:2018-02-28 10:53:44

标签: reactjs jestjs enzyme

在我的反应组件中,我导入反应,然后我需要一个数据文件。

const data = require(data.txt);

txt文件包含我只需要的xml数据。 xml保存用于最初使用一些虚拟数据渲染组件的数据。所以在我的spec文件中我想要执行快照。

import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from '../';

test('renders a component', () => {
  const wrapper = shallow((
    <MyComponent />
  ));

  expect(wrapper).toMatchSnapshot();
});

运行测试后,我收到错误:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<?xml version="1.0" encoding="UTF-8"?>

SyntaxError: Unexpected token <

这就是xml正好开始的地方。这与变压器有关吗?如何解决这个问题?

0 个答案:

没有答案