mardi 4 août 2015

how to test custom directive with jasmine?

i make a custom directive in my app and now want to unit test it with karma and jasmine but my test gets failed here is my directive:

  <div my-data remoteurl='url' filter='test' order-by='sortExpression' order='order' >
    </div>

myappcontroller:

       (function() {

          'use strict';

         var myApp = angular.module('myApp', [])
.controller('myAppCtrl', ['$scope', '$http', function($scope, $http) {
  $scope.url = 'http://ift.tt/1KEkUhj';
  $scope.filter= 'test';
  $scope.orderBy= 'sortExpression';
  $scope.order= 'orderBy';
}])
.directive('myData', ['$http', function($http) {
  return {
    restrict: 'A',
    scope: {
      remoteurl: '=',
      filter: '=',
      orderBy: '=',
      order: '='
     // orderBy:'sortExpression':'order' ;
    },
    templateUrl: 'DataTable.html',
    link: function(scope, element, attr) {

      $http.get(scope.remoteurl)
        .success(function(response) {
          scope.names = response.data.children;
        });
    }
  };
}]);

})(); when i run this i will get this error:

       C:\wamp\www\First-angular-App>karma start karma.conf
        INFO [karma]: Karma v0.12.16 server started at        http://localhost:9876/
       INFO [launcher]: Starting browser Chrome
       INFO [Chrome 44.0.2403 (Windows 8)]: Connected on socket    TEd9Xo5aEr_WPAJCbfjc wi
      th id 79057650
      Chrome 44.0.2403 (Windows 8) unit testing directive order style should be false
     in the beginning FAILED
      Error: Unexpected request: GET DataTable.html
      No more request expected
         at $httpBackend (C:/wamp/www/First-angular-   App/bower_components/angu
      lar-mocks/angular-mocks.js:1178:9)

how can i do this ? Any suggestion will be greatly appreciated as i am get stuck here so guide me i am new to angular.

Aucun commentaire:

Enregistrer un commentaire