【发布时间】:2017-12-25 18:15:03
【问题描述】:
我正在尝试为组件编写测试用例。测试用例正在通过。但是 JS lint 困扰着我。它抛出一个错误 - :期望一个赋值或函数调用,而是看到一个表达式
错误来了:expect(dummyOutput.find('h1.screen-reader-text')).to.exist;
我的完整测试用例代码如下。谁能帮我解决这个错误吗?
import React from 'react';
import { shallow } from 'enzyme';
import Page from './page';
const props = {
pageLayout: 'article',
theme: 'test-theme',
header: {},
footer: {},
singleAds: {},
siteMeta: { copyright_text: '©COPYRIGHT CONTENT HERE' },
};
const dummyProps = {
pageLayout: 'dummy_text',
theme: 'test-theme',
header: {},
footer: {},
singleAds: {},
siteMeta: { copyright_text: '©COPYRIGHT CONTENT HERE' },
};
const specs = () => describe('Page Layout', () => {
describe('Renders', () => {
const wrapper = shallow(<Page {...props} />);
const dummyOutput = shallow(<Page {...dummyProps} />);
it.only('should not return H1 tag', () => {
expect(wrapper.find('h1.screen-reader-text')).not.exist;
});
it.only('should return H1 tag', () => {
expect(dummyOutput.find('h1.screen-reader-text')).to.exist;
});
});
});
if (process.env.NODE_ENV === 'test') {
specs();
}
export default specs;
【问题讨论】:
-
我曾经遇到过类似的问题 - 我在这个问题中得到了帮助:stackoverflow.com/questions/37558795/…,也许它可以帮助你
标签: reactjs enzyme testcase chai-enzyme