简体   繁体   English

JSLint抛出错误-预期分配或函数调用,而是看到一个表达式

[英]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.

相关问题 在地图函数中渲染会导致 JsLint 错误,如预期的赋值或函数调用,而是看到了一个表达式? - Rendering in a map function lead to a JsLint error as Expected an assignment or function call and instead saw an expression? 期望赋值或函数调用,但在函数中看到表达式错误 - Expected an assignment or function call and instead saw an expression error in function ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” 预期分配或 function 调用,而是看到一个表达式(错误) - Expected an assignment or function call and instead saw an expression(error) 反应错误 [期望赋值或函数调用,而是看到一个表达式] - React error [Expected an assignment or function call and instead saw an expression] 第 14 行期望一个赋值或函数调用,但看到一个表达式错误 - line 14 Expected an assignment or function call and instead saw an expression error React JS 错误:预期分配或 function 调用,而是看到一个表达式 - React JS error : Expected an assignment or function call and instead saw an expression Eslint 错误:'预期分配或 function 调用,而是看到一个表达式' - Eslint Error: 'Expected an assignment or function call and instead saw an expression' 预期一个赋值或 function 调用,而是看到一个表达式错误 - Expected an assignment or function call and instead saw an expression error 预期分配或 function 调用,而是看到一个表达式:没有未使用的表达式 - Expected an assignment or function call and instead saw an expression : no unused expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM