javascript - Testing Angular Factory with Jasmine is not working -


i'm new jasmine. i've written simple code execute in js fiddle working fine. but, when include jasmine code, not working. missing here?

var app = angular.module('sortmodule', []) app.factory('sortfactory', function(){     var sortedcolors = [] var shouldpush = true; return {     sortcolors: function(colorsarray){         var colorsorder = [{color:'green'},{color:'yellow'},{color:'blue'},{color:'red'}]             for(color in colorsorder) {         for(objcolor in colorsarray)     {             shouldpush = colorsorder[color].color === colorsarray[objcolor].color ? true : false           if(shouldpush) {sortedcolors.push(colorsarray[objcolor]);}          }       }       return sortedcolors;     } }                }); app.controller('sortcontroller', function($scope,sortfactory){         $scope.colorsarray = [{id: '1',color: 'red',code : '#ff0000'},{id: '2',color: 'blue',code : '#0000ff'},{id: '3',color: 'red',code : '#ff0000'},{id: '4',color: 'yellow',code : '#ffff00'},{id: '5',color: 'green',code : '#00ff00'}];     $scope.sortedcolors = sortfactory.sortcolors($scope.colorsarray)  });  describe('colors', function () {      beforeeach(module('sortmodule'));     it('can actual sorted ordered colors list', inject(function(sortfactory) {     expect(sortfactory).tobedefined(); }));     });  var not_implemented = undefined;  // load jasmine htmlreporter (function() {   var env = jasmine.getenv();   env.addreporter(new jasmine.htmlreporter());   env.execute(); }()); 

actual working fiddle without jasmine http://jsfiddle.net/syednizamchennai/kjuemhua/15/

new fiddle when jasmine included

https://jsfiddle.net/syednizamchennai/5d4f0hdl/3/ 

test code contains module function

beforeeach(module('sortmodule')); 

this function ngmock module, need include external resource.

https://jsfiddle.net/syednizamchennai/5d4f0hdl/3/

edit:

working example here: http://jsbin.com/lenogujesi/1/edit?html,output

(i used jsbin better show dependencies , order)

some notes:


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -