Jest: Test suite failed to run TypeError: Path must be a string. Received undefined

Created on 29 Sep 2017  路  2Comments  路  Source: facebook/jest

I'm trying to write the test cases for my react components in jest and I'm using the following code as a reference. jest for react. And my component is

``import React, { Component } from 'react';
import Modal from './commons/modal';
import StartContainer from './startContainer';
import Header from './commons/header';

//import '../css/remote.scss';
//import '../css/virtual.scss';
import {Router , Route , browserHistory} from 'react-router';

class MainContainer extends Component{
constructor(props){
super(props);

};
executeHome(){
var getCurrentScrollPos = function(){ return window.scrollY; };
var heroBanner = document.querySelector('.aw-offset-height');

var headerClassList = '';
var offsetHeight = function(){
  if(heroBanner)
    return heroBanner.offsetHeight;
    return 0;
  };
  var scrollPosition = function(){return offsetHeight()};
  var feature = document.querySelector('.aw-dynamic-top');
  var fadeStart = 0; // 0 scroll or less will equiv to 0 opacity
  var overlay = document.querySelector('.overlay');
  var opacity = 0;
  var header = document.getElementsByTagName('header')[0];
  var responsive_menu = document.getElementById("responsive-menu");

  function handlePageScroll() {
    var currentScrollPos = getCurrentScrollPos();
    if(header){
        headerClassList = header.classList;
        if((currentScrollPos + header.clientHeight) >= scrollPosition()){
          if(!headerClassList.contains('animate')) {
              headerClassList.add("animate");
            }
          }else{
              headerClassList.remove("animate");
            }
          }
          if(heroBanner){
            if(heroBanner.classList.contains('aw-hero-banner')){
              if( currentScrollPos<=fadeStart ){
                opacity = 0;
              }else if( currentScrollPos<= offsetHeight() ){
                opacity=1*currentScrollPos/offsetHeight();
              }
              overlay.style.opacity= opacity;
            }
          }
        };
        if(feature)
          feature.style.marginTop = offsetHeight() + 'px';

// Resize Function
window.onresize=function(){
if(feature)
feature.style.marginTop = offsetHeight() + 'px';
handlePageScroll();
};
var _handleMenuNavigation = function(event){
var target = event.target;
try{
if(target.parentElement.parentElement.nodeName === "MAIN"){
target.parentElement.classList.add("opened");
return;
}
target.parentElement.parentElement.classList.add("opened");
}catch(err){
console.error("Error in _handleMenuNavigation",err);
}
};
if(responsive_menu){
responsive_menu.addEventListener("click",_handleMenuNavigation);
}

window.onscroll= function(){
handlePageScroll();
};
}
componentDidMount(){
this.executeHome();
}
render(){
return(






)
}
}
export default MainContainer;``

And my jest.config.js

{ "moduleFileExtensions" : [ "js", "jsx" ], "moduleNameMapper": { "mainContainer" : "<rootDir>/app/mainContainer.js" } }
And my render.test.js

import React from 'react'; import ReactDOM from 'react-dom'; import { shallow } from 'enzyme'; import MainContainer from 'startContainer'; describe('mainContainer', () => { it('renders without crashing', () => { const div = document.createElement('div'); ReactDOM.render(<MainContainer />, div); }); });

I'm getting the following error while running

Most helpful comment

If you're still having the same issue, see this stackoverflow article. The solution worked for me.

All 2 comments

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)

If you're still having the same issue, see this stackoverflow article. The solution worked for me.

Was this page helpful?
0 / 5 - 0 ratings