【问题标题】:Jasmine Unit Testing: Error: Cannot find module 'parser.js'Jasmine 单元测试:错误:找不到模块“parser.js”
【发布时间】:2023-03-30 04:51:01
【问题描述】:

我是单元测试的新手,我刚刚安装了 jasmine 并编写了这个测试程序。

   var grabNums = require('parser')

describe("parsenpmr test", function(){
    it(" .3grabs possible phone and conference numbers", function(){
        expect(grabNums.grabNums("the phone number is (914)-817-3535 and the conference code is 5852753333 please call in at 6:00AM").toBe(['(914)8173535','5852753333']))
    })
})

My Directory organization looks like this at the moment

这是我遇到的错误

> outlookparser2@1.0.0 test C:\Users\kaizert\eclipse-workspaceREAL\client_S4B\src\outlookParser2
> jasmine

module.js:549
    throw err;
    ^

Error: Cannot find module 'parser.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\kaizert\eclipse-workspaceREAL\client_S4B\src\outlookParser2\spec\parserspec.js:1:78)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
npm ERR! Test failed.  See above for more details.

我需要改变什么?再次,我是单元测试的新手,所以如果有一个简单的解决方案,我很抱歉,我在网上找不到任何东西。

【问题讨论】:

  • 您是否安装了您正在使用的模块parser
  • Parser 是我制作的 .js 文件,其中包含我想测试的功能。其中每个函数都有对应的module.exports.functionName语句
  • 你能分享它的代码和文件夹结构吗?

标签: javascript unit-testing jasmine


【解决方案1】:

我想解决方法是: var parser = require('./parser');

【讨论】:

    【解决方案2】:

    我发现了我的问题。我不怀疑这对许多其他人来说是个问题,但我不正确地引用了我的实际 .js 文件。我有

    var parser = require('parser');
    

    我应该有的时候

    var parser = require('parser');
    

    【讨论】:

    • 两者有什么区别?
    猜你喜欢
    • 2016-06-05
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    相关资源
    最近更新 更多