ReactJs Enzyme shallow returns undefined for renderless component reactjs enzyme tutorial,reactjs enzyme,react enzyme testing,reactjs enzyme

This is my js file

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;
  }
}

I wrote a test case for the same like below:

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);
  });
});

but when I executed npm test it returned:

ReferenceError: ProjectStore is not defined

What am I doing wrong here?

Answer:1



  1. reactjs enzyme tutorial
  2. reactjs enzyme
  3. react enzyme testing
  4. reactjs enzyme redux
  5. react enzyme mock
  6. enzyme reactjs test cases
  7. enzyme react js config
  8. enzyme react js node

I am using two main layouts with react router like below. I have written AppRoute component to use different layouts with switch. Problem is when i come back to "/" home from "/login" or "/register" ...

I am using two main layouts with react router like below. I have written AppRoute component to use different layouts with switch. Problem is when i come back to "/" home from "/login" or "/register" ...

I have an array of times in state I use to calculate an average time, also in state. this.state = { avgTime: null, allTimes: [] } then the method to do the calculation: this.getTime = () => {...

I have an array of times in state I use to calculate an average time, also in state. this.state = { avgTime: null, allTimes: [] } then the method to do the calculation: this.getTime = () => {...