Reputation: 2580
I'm using lodash in my application/component. Jasmine is complaining:
Failed: Cannot read property 'eq' of undefined
I've added, lodash to my karma.conf
such as:{ pattern: './node_modules/lodash/lodash.min.js', included: true, watched: false }
Still getting the issue, what is the correct way of including lodash?
Upvotes: 2
Views: 3836
Reputation: 61
I solved this problem by adding these lines to "main.ts":
//...
import _ from 'lodash';
declare global {
const _: _.LoDashStatic;
}
//...
Also, I added lodash to karma.conf.js:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
files: [
'node_modules/lodash/lodash.js'
],
//...
Upvotes: 3
Reputation: 71
Just import lodash like this in your component:
import * as _ from 'lodash'
Upvotes: 7