Jasmine 无法引用在其他js文件中编写的函数

Jasmine 无法引用在其他js文件中编写的函数,jasmine,protractor,Jasmine,Protractor,当我使用下面的代码时,我得到一个错误 使用的工具:量角器 框架:茉莉花 IDE:Webstorm //Page object file - newPage.js newPage = function(){ function clickCandidate(){ //All your code that you want to call from the test spec }); }; module.exports = new newPage(); //Test

当我使用下面的代码时,我得到一个错误

使用的工具:量角器
框架:茉莉花
IDE:Webstorm

//Page object file - newPage.js
newPage = function(){
    function clickCandidate(){
        //All your code that you want to call from the test spec
    });
};
module.exports = new newPage();

//Test Spec file - test.js
var newPage = require('./newPage.js'); //Write the location of your javascript file
it('Click on candidate status Screened', function () {
    //Call the function
    newPage.clickCandidate();
});
我得到的错误是:

错误:找不到模块“scenarios/newPage.js”


首先,当然要确保
require
path是正确的,并且是相对于正在运行的文件的

除此之外,还有几件事引起了我的注意:

  • newPage=function()之前添加
    var
  • 也可以尝试使用
    这个
    或原型继承
  • 所以它可能看起来像这样:

    var newPage = function () {
        this.clickCandidate(){
            //All your code that you want to call from the test spec
        });
    };
    module.exports = new newPage();
    

    var newPage = function() {};
    
    newPage.prototype.clickCandidate = function() {
        // all your code
    };
    
    module.exports = new newPage();