3

I want to use lodash functions in my protractor spec, I'm using _.forEach() to fill a form with values.

How do I get lodash into my protractor script so that I can use it?

I'm not asking how to use it in my app, but in the actual running protractor scripts

boatcoder
  • 17,525
  • 18
  • 114
  • 178

1 Answers1

4

You can use the native Array.forEach(). If you need lodash do this:

Get the node dependency.

npm install lodash --save-dev

Then use it in your test.

var _ = require('lodash');

describe('foo', function() {
  it('should do stuff', function() {
    _.each();
  });
})
Andres D
  • 8,910
  • 2
  • 26
  • 31
  • I'm glad you added the info about npm install. I already had lodash installed with bower, but require('lodash') failed until I also installed it with npm. – boatcoder Aug 24 '14 at 11:43
  • 1
    @Mark0978 Just to expand on your findings, bower is used to install front-end components while NPM is used to install node packages. Installing lodash with bower allows it to be used 'on-page in browser' (similar to how you'd use jQuery). Installing it with NPM allows it to be used by Node itself. – Jackson Hyde Oct 28 '14 at 14:33
  • you have to add b browserify as well . http://stackoverflow.com/questions/19117092/jasmine-tests-in-karma-uncaught-referenceerror-require-is-not-defined – Anja Ishmukhametova Mar 14 '17 at 06:24