Javascript 返回未定义的无渲染组件

Javascript 返回未定义的无渲染组件,javascript,reactjs,jestjs,enzyme,Javascript,Reactjs,Jestjs,Enzyme,这是我的js文件 import React, { Component } from 'react'; export default class ProjectStore extends Component { static lodingCount = 0; constructor(props) { super(props); } static setLodingCount(countValue){ ProjectStore.lodingCount = coun

这是我的js文件

import React, { Component } from 'react';

export default class ProjectStore extends Component {
  static lodingCount = 0;
  constructor(props) {
    super(props);
  }

  static setLodingCount(countValue){
    ProjectStore.lodingCount = countValue;
  }

  static getLodingCount(){
    return ProjectStore.lodingCount;
  }
}
我编写了一个测试用例,如下所示:

import React from 'react';
import {shallow} from 'enzyme';
import ProjectStore from '../projectStore.js';

describe('<ProjectStore />', () => {
  it('should return loading count', () => {
    const ProjectStore = shallow(<ProjectStore />);
    ProjectStore.setLodingCount(2);
    expect(ProjectStore.lodingCount).toEqual(2);
  });
});

这里我做错了什么?

当从类测试静态方法时,不需要呈现该组件。您只需从该类调用该静态方法,如下所示:

import React from 'react';
import Adapter from 'enzyme-adapter-react-16';

import ProjectStore from './projectStore.js';

describe('<ProjectStore />', () => {
  it('should return loading count', () => {
    ProjectStore.setLodingCount(2);
    expect(ProjectStore.lodingCount).toEqual(2);
  });
});
从“React”导入React;
从'enzyme-Adapter-react-16'导入适配器;
从“./ProjectStore.js”导入ProjectStore;
描述(“”,()=>{
它('应返回加载计数',()=>{
ProjectStore.setLodingCount(2);
期望(ProjectStore.lodingCount)。toEqual(2);
});
});

您可以从中了解更多。

谢谢@konekoya为我工作。还有一件事,你能建议我如何在这种情况下为构造函数方法编写测试用例吗?@rahul最好在单独的问题中提问
import React from 'react';
import Adapter from 'enzyme-adapter-react-16';

import ProjectStore from './projectStore.js';

describe('<ProjectStore />', () => {
  it('should return loading count', () => {
    ProjectStore.setLodingCount(2);
    expect(ProjectStore.lodingCount).toEqual(2);
  });
});