错误:找不到模块 'jasmine-expect' [量角器]

Posted

技术标签:

【中文标题】错误:找不到模块 \'jasmine-expect\' [量角器]【英文标题】:Error: Cannot find module 'jasmine-expect' [Protractor]错误:找不到模块 'jasmine-expect' [量角器] 【发布时间】:2016-09-04 08:58:18 【问题描述】:

我正在尝试运行一个简单地连接到我的应用程序的量角器测试。

当我运行时(git bash/终端):

   protractor conf.js

我收到以下错误:“

错误:找不到模块'jasmine-expect'

看到这个后,我继续安装模块:

npm install -g jasmine-expect

但我仍然收到同样的失败。

这是我的测试:

describe('DragAndDrop Test', function () 
require('protractor');
require('jasmine-expect');


beforeAll(function () 
    context = new Context();
    context.get();
    browser.waitForAngular();
    browser.driver.manage().window().maximize();
);

it('should drag and drop Application Experience tile', function () 

    //target is where we are dragging the box to.  Box is the Box
    var target =  x: 300, y: 50 ;
    var box = element(by.cssContainingText('h3', 'Application Experience'));

    //scope is going to hold the scope variables that tell us where the box is located
    //get the standardItems Scope

    box.evaluate('dashboards').then(function(scope) 
        //make sure the box we are using is initially set in column 0 and Row 0
        expect(scope['1'].widgets[0].col).toEqual(0);
        expect(scope['1'].widgets[0].row).toEqual(0);
    );

    //drag and drop the box somewhere else.
    browser.actions().dragAndDrop(box, target).perform();
    browser.waitForAngular();
    browser.driver.sleep(5000);

    //get the updated scope
    box.evaluate('dashboards').then(function(scope) 
        //test to see that the box was actually moved to column 1 and row 0
        expect(scope['1'].widgets[0].col).toEqual(1);
        expect(scope['1'].widgets[0].row).toEqual(0);
    );
);

);

var Context = function () 
this.ignoreSynchronization = true;
    //load the website
    this.get = function () 
        browser.get('http://127.0.0.1:62734/index.html#/dashboard');
    ;
;

这是我的 conf.js:

exports.config = 
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['gridster-Test.js'],
    capabilities: 
    browserName: 'firefox'
   
;

有什么建议吗?

【问题讨论】:

【参考方案1】:

确保将依赖项添加到您的 package.json 文件中。

npm install jasmine-expect --save-dev 

【讨论】:

【参考方案2】:

首先,尝试在不使用-g 标志的情况下安装软件包:

npm install jasmine-expect

另外,将require('jasmine-expect');describe 下移动到Protractor 配置文件中的onPrepare()

onPrepare: function () 
    require("jasmine-expect");
,

【讨论】:

除了您建议的 onPrepare() 之外,尝试在没有 -g 标志的情况下进行安装。相同的错误信息。它找不到茉莉花期望。它安装成功,所以我不知道发生了什么。

以上是关于错误:找不到模块 'jasmine-expect' [量角器]的主要内容,如果未能解决你的问题,请参考以下文章

无法启动 Terminal Services 服务。错误 126: 找不到指定的模块。

错误找不到模块'@angular/material

Phonegap 错误 + 错误:找不到模块 'q'

解析错误:找不到模块'next/babel'

找不到模块:错误:无法解析模块“fs”

TypeOrm 迁移 - 错误:找不到模块