[英]JSLint is throwing an Error - Expected an assignment or function call and instead saw an expression
Am trying to write a test case for a component. 我正在尝试为组件编写测试用例。 Test cases are getting passed.
测试用例正在通过。 But JS lint is bugging me.
但是JS皮棉在烦我。 Its throwing an error - :Expected an assignment or function call and instead saw an expression
它抛出错误-:预期分配或函数调用,而是看到一个表达式
The error is coming here : expect(dummyOutput.find('h1.screen-reader-text')).to.exist; 错误将在这里出现:Expect(dummyOutput.find('h1.screen-reader-text'))。to.exist;
My complete testcase code is as below. 我完整的测试用例代码如下。 Can anyone help me here to solve the error please?
有人可以在这里帮助我解决错误吗?
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;
It will warn you about this when it sees an expression on a line where it isn't being assigned to anything. 当它在未分配任何内容的行上看到表达式时,它将对此警告您。 For example,
例如,
1 + 1
will make it complain because it just evaluates and does nothing, which the linter thinks is unintended. 会抱怨它,因为它只是评估而什么也不做,而lint认为这是意料之外的。 It likes to see an assignment like
喜欢看像这样的作业
const x = 1 + 1
In your case I think it is interpreting that line as an expression that isn't being used for anything because it sees that in the end you are accessing a property of a property of the result of the function (.to.exist) but you aren't doing anything (as far as it can tell) with that value. 在您的情况下,我认为它将那条线解释为未用于任何内容的表达式,因为它最终看到您正在访问函数结果(.to.exist)的属性的属性,但是您并没有用该值做任何事情(就其所能告诉的)。
If you want to make it stop complaining, maybe you could try adding a return: 如果您想让它停止抱怨,也许您可以尝试添加回报:
return expect(dummyOutput.find('h1.screen-reader-text')).to.exist;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.