Kode_12 Kode_12 - 9 months ago 58
AngularJS Question

Error: Cannot find module 'jasmine-expect' [Protractor]

Im trying to run a protractor test that simply connects to my application.

When I run (git bash/terminal):

protractor conf.js


I receive the following error: "


Error: Cannot find module 'jasmine-expect'


After seeing this, I went ahead and installed the module:

npm install -g jasmine-expect


But I still receive the same failure.

Here is my test:

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');
};
};


Here is my conf.js:

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


Any suggestions?

Answer Source

First of all, try installing the package without using the -g flag:

npm install jasmine-expect

Also, move the require('jasmine-expect'); from under the describe into the onPrepare() in your Protractor configuration file:

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