mardi 24 novembre 2020

while testing a component with Chai a error is being displayed Cannot read property 'indexOf' of undefined , how to solve it?

I am new to react and as well as testing in react, so while i am trying write a simple test to test whether a a component is rendered by using - expect(container.length).to.equal(1) I am getting an error - TypeError: Cannot read property 'indexOf' of undefined.

import { shallow } from 'enzyme'
import App from './App'

describe('local test', ()=>{


    it('should render', ()=>{
        let container = shallow(<App/>)

        expect(container.length).to.equal(1)
    })

})

this code for my App.js

import React,{Component} from 'react'
import Product from './components/Product'
import Filter from './components/Filter'


import { connect } from 'react-redux'



class App extends Component {


  render(){
    return (
    
      <div className ="grid-container">
        <header>
          <a href="/">React Shopping Cart</a>
        </header>
        <main>
          <div className="content">
            <div className="main">
              <Filter />
              <Product></Product>
            </div>
            
           
          </div>
       
        </main>
      
       
      </div>

     )
  }
 
}


Aucun commentaire:

Enregistrer un commentaire