mardi 24 janvier 2017

AngularJS Test Factory Function with dependencies in Jasmin

I have a factory function which has two dependencies. The factory function only checks if a value is already in a array or not.

this is my factory function :

.factory('GetResultFile',
    ['$http', '$q',
    function ($http, $q) {

        var service = {};

        //service function for checking, if item is already in the array
        service.arrayCheck = function(status, items) {

            var i = 0;
            var len = items.length;

            for (i = 0; i < len; i++) {
                //if item is already in array: delete item
                if(status === items[i].status) {
                    return i;
                }
            }
            return -1;
        }

now i want to check if a element is in the array or not, therefore i have create this test in jasmine :

'use strict';

describe("Test all services from the home module", function() {

    beforeEach(module('Home'));

    describe("when I call factory method: GetResultFile", function() {

        it("when I call factory method: GetResultFile.arrayCheck", inject(function(GetResultFile) {
            var statusInArray = 'SETUP';
            var statusNotInArray = 'DONE';
            var statusList = [{'id': 1, 'status': 'SETUP'}, {'id': 2, 'status': 'TEST'}];

            expect(GetResultFile.arrayCheck(statusInArray, statusList)).not.toEqual(-1);
            expect(GetResultFile.arrayCheck(statusNotInArray, statusList)).toEqual(-1);
        }))

    })

});

if i start karma, it don't find the GetResultFile factory function :/

Sorry i am new with jasmine

Aucun commentaire:

Enregistrer un commentaire