vendredi 18 décembre 2015

How can I use _ library in Angular unit test

I'm trying to unit test a simple function in a factory, but I'm using underscorejs library in the code.

Code to test:

        var unpackOrderData = function(data){
        var paramsToUnpack = ["created_at", "total_price"];

        var unpackedArray = _.map(data, function(largeObj){
            return _.pick(largeObj, paramsToUnpack);
        });

        _.each(unpackedArray, convertTimeToMillis);

        _.each(unpackedArray, convertJSONToArray);

        var returnValue = [unpackedArray];
        return returnValue;
    };

app.js:

.constant('', window. )

    beforeEach( 
    inject(function(_$rootScope_, _$httpBackend_, _OrderDataFactory_, ___) {
        $rootScope  = _$rootScope_;
        _ = ___;
        httpBackend = _$httpBackend_;
        httpBackend.whenGET('http:/localhost:1000/orders').respond(200, dataToCompare);

        orderDataFactory = _OrderDataFactory_;
    }) 
);

Then I'm getting the following error from karma results: TypeError: 'undefined' is not an object (evaluating '_.map')

Any ideas how I can inject this dependency into my tests?

Aucun commentaire:

Enregistrer un commentaire