簡體   English   中英

JSLint拋出錯誤-預期分配或函數調用,而是看到一個表達式

[英]JSLint is throwing an Error - Expected an assignment or function call and instead saw an expression

我正在嘗試為組件編寫測試用例。 測試用例正在通過。 但是JS皮棉在煩我。 它拋出錯誤-:預期分配或函數調用,而是看到一個表達式

錯誤將在這里出現: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;

當它在未分配任何內容的行上看到表達式時,它將對此警告您。 例如,

1 + 1

會抱怨它,因為它只是評估而什么也不做,而lint認為這是意料之外的。 喜歡看像這樣的作業

const x = 1 + 1 

在您的情況下,我認為它將那條線解釋為未用於任何內容的表達式,因為它最終看到您正在訪問函數結果(.to.exist)的屬性的屬性,但是您並沒有用該值做任何事情(就其所能告訴的)。

如果您想讓它停止抱怨,也許您可​​以嘗試添加回報:

return expect(dummyOutput.find('h1.screen-reader-text')).to.exist;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM