angularjs - Unit Test not giving expected error on grunt dev-test check -
i trying begin run unit tests while learning mean using grunt dev-test check following, should return error. however, in terminal grunt dev-test detects file being changed , reports no errors.
'use strict'; describe('appmydirective', function() { var elm, elmscope, $scope, $compile, $timeout; beforeeach(module('myapp')); /** @param params @param {string} html */ var createelm =function(params) { var html ="<div app-my-directive>"+ "</div>"; if(params.html) { html =params.html; } // elm =angular.element(html); elm =$compile(html)($scope); // $scope.$digest(); $scope.$apply(); //note: required otherwise alert directive won't compiled!!!! ... wtf? elmscope =elm.isolatescope(); var elements ={ // 'somepart':elm.find('div').children().find('div') }; return elements; }; beforeeach(inject(function(_$rootscope_, _$compile_, _$timeout_) { $compile = _$compile_; $timeout = _$timeout_; $scope = _$rootscope_.$new(); })); // aftereach(function() { // }); it('should have scopeone property', function() { $scope.scopeone ='test scope one'; var html ="<div app-my-directive scope-one='scopeone'></div>"; createelm({html:html}); expect(elmscope).tobe('test scope one1'); }); }); since $scope.scopeone ='test scope one'; , expect 'test scope one1' should not pass 'untruthy'. or doing wrong here?

directive code:
/** @toc @param {object} scope (attrs must defined on scope (i.e. in controller) - can't defined in partial html). remember: use snake-case when setting these on partial! @param {string} scopeone scope property @param {function} funcone custom function todo @param {object} attrs remember: use snake-case when setting these on partial! i.e. my-attr='1' not myattr='1' todo @param {string} customtext special text @dependencies todo @usage partial / html: <div app-my-directive></div> todo controller / js: todo //end: usage */ 'use strict'; angular.module('app').directive('appmydirective', [ function () { return { restrict: 'a', scope: { scopeone: '=', funcone: '&?' }, // replace: true, template: function(element, attrs) { var defaultsattrs ={ }; for(var xx in defaultsattrs) { if(attrs[xx] ===undefined) { attrs[xx] =defaultsattrs[xx]; } } if(!attrs.customtext) { attrs.customtext = ''; } var html ="<div class='app-my-directive-cont'>"+ "custom text: "+attrs.customtext+ "<br/>scope one: {{scopeone}}"+ "<br/>scope two: {{scopetwo}}"+ "<div class='btn' ng-click='emitevt()'>emitevt</div>"+ "<div class='btn' ng-click='funcone()'>funcone</div>"+ "</div>"; return html; }, link: function(scope, element, attrs) { }, controller: function($scope, $element, $attrs) { $scope.scopetwo = 'scope two'; $scope.emitevt =function() { $scope.$emit('appmydirectiveevt1', {}); var log = 'suck js works.'; console.log(log); }; } }; }]); entire project: https://github.com/tuffs/mean
please provide code directive have "expected undefined 'test scope one1'." - feel free execute tests "run code snippet"
angular.module('myapp', []) describe('appmydirective', function() { var elm, $scope, $compile; beforeeach(module('myapp')); var createelm = function(params) { var html = "<div app-my-directive>" + "</div>"; if (params.html) { html = params.html; } elm = $compile(html)(params.scope); params.scope.$apply(); //note: required otherwise alert directive won't compiled!!!! ... wtf? return elm.isolatescope(); }; beforeeach(inject(function(_$rootscope_, _$compile_) { $compile = _$compile_; $scope = _$rootscope_.$new(); })); it('should have scopeone property', function() { $scope.scopeone = 'test scope one'; var elmscope = createelm({ html: "<div app-my-directive scope-one='scopeone'></div>", scope: $scope }); expect(elmscope).tobe('test scope one1'); }); }); <link href="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine.css" rel="stylesheet" /> <script src="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine-2.0.3-concated.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-mocks.js"></script>
Comments
Post a Comment