Tagged Questions
0
votes
1answer
43 views
Writing unit test for AngularJS directive with Jasmine?
I am new to the world of JavaScript and Angular, and I am using Karma and Jasmine to test code. I am having a difficult time figuring out how to test angular directive.
The directive validates the ...
3
votes
3answers
165 views
Trying to test AngularJS directives with a templateURL
In my karma.conf.coffee, I have:
files: [
'public/bower_components/angular-mocks/angular-mocks.js'
'public/scripts/**/*.coffee' # not tested since configuration is difficult to be tested and ...
0
votes
0answers
21 views
Compile inside test don't create the required result
I'm using karma for unit test my angular directive. I've removed parts from my directive until I removed it all, but I'm obviously missing something.
this is the test:
element = ...
0
votes
1answer
84 views
$timeout, triggering app initialization in angular directive test and $httpBackend mock error
I'm having an issue with a test (Karma+Mocha+Chai). I'm testing a pretty simple directive, part of a bigger angular module (webapp). The issue is that, when calling $timeout.flush() in my test, the ...
0
votes
1answer
82 views
When unit testing AngularJS directive, urlIsSameOrigin function fails
This is my first test for an AngularJS directive, it's possible I'm missing something very basic.
When running my test suite I get an error after the $compile function got called: when it is trying ...
0
votes
1answer
21 views
mock an AngularJS directive
I have the following directive:
function InfoListDirective($rootScope, $restApi) {
return {
restrict: 'A',
templateUrl: staticFilesUri + 'templates/InfoList.Template.html',
...
0
votes
0answers
24 views
Testing AngularJS Directive does'nt replace template
I'm using karma-ng-html2js-preprocessor.
The directory structure is like
-app
--directives
---gamelabel
----gamelabel.js
----gamelabel.html
-test
--gamelabel.test.js
karma.conf.js:
...
1
vote
1answer
58 views
Angularjs directive unit test issue
I am trying to fill ng-repeat (home.html) with a directive named 'card' as written below. CardProvider is promise object which is loading content with $http.
Each directive in ng-repeat adding html ...
1
vote
1answer
27 views
AngularJS : How to test directive with many dependencies
I'm trying to test a directive since a few days and I can't find any good ways.
A bit of context : We are using Facebook to login and get a friends list at bootstrap. This list of friends is stored ...
0
votes
0answers
31 views
element.bind does not work in unit test whereas element[0].addEventListener does
I want to test double click events in directives with unit tests.
The solution I found is to generate the event with this (in the unit test):
var ev = document.createEvent('MouseEvent');
...
0
votes
1answer
43 views
Unit-testing a directive with isolated scope, bidirectional value and ngIf
I want to unit test a directive which looks like this:
angular.module('myApp', [])
.directive('myTest', function () {
return {
restrict: 'E',
scope: { message: '='},
...
0
votes
0answers
58 views
jasmine test for window.bind() in angular directive
I have a directive which has the below which i need to test in jasmine.
angular.element($window).bind('scroll', function () {
scrollFunc(element);
});
...
0
votes
0answers
11 views
Error in unit test of anuglarjs directive
The below directive checks/loads the template with value "pass, fail, required".
The conditions are
if(parent value == required){
1. if the value is true --> $scope.msg = "fail" --> loads the ...
0
votes
2answers
107 views
angular directive unit testing with jasmine with template and link
I have a directive as below which i want to cover as part of my jasmine unit test but not sure how to get the template value and the values inside the link in my test case. This is the first time i am ...
0
votes
1answer
65 views
Angular.js: testing click on directive
I have an Angular.js directive which I am trying to write a test for. Basically, it is a wrapper for a checkbox, such as that when the wrapper is clicked, the checkbox's state is changed. The problem ...
0
votes
0answers
24 views
Testing onkeypress event with jasmin
I have written an angular directive that allows only character input. For this I have used onkeypress event in the link function. below is the directive code:
demoApp.directive('sTextField', ...
0
votes
1answer
42 views
Unable to retrieve templates in angular unit tests for directives with karama, grunt, and yeoman-maven-plugin
I'm in a less than ideal situation where I need to work with both grunt and maven within a single build. My directory structure looks like the following:
project
+-src
| +-main
| +-webapp
| ...
0
votes
0answers
71 views
Testing Directives events
I have a directive that $emit's an event, but in the parent scope of a unit test doesn't get the event.
test $broadcasts an event to the directive, directive gets the event, and then directives ...
0
votes
1answer
109 views
Karma tests fail but debug shows pass
I'm having an issue where I run my jasmine unit tests in Karma, and one of my unit tests that depends on an external template (AngularJS directive) doesn't pass. When I go into DEBUG mode in the ...
0
votes
0answers
116 views
Unit Testing Angular Directive that listens for 2 connected events
I have implemented a ctrl + click open a new tab directive in Angular.
I am having troubles unit testing the second event, which depends on the first event.
My question is how do I simulate a ...
0
votes
1answer
41 views
Testings Directives Controller AngularJS Karma
I cannot access controllers values, everything is undefined. I can see the values in the log, but cannot access them. Is there a preferred way to creating directives and testing its controllers. I ...
0
votes
0answers
63 views
angularjs: Unit testing with simulate click
I'm unit testing a directive, and I have something like this
<bar-foo>
<a ng-click=show = !show">click me</a>
</bar-foo>
var scope = el.isolateScope();
...
0
votes
0answers
22 views
Unittesting angular directives with external templates
I am trying to unittest our angular directives which are implemented with external templates.
As far as I can find there are only two options:
use $httpBackend to respond with the template when ...
0
votes
2answers
156 views
AngularJS Unit testing a link in a directive
I am trying to write unit tests to test my directives. However, when I invoke a click on a checkbox, it will not update the model.
How can I make it change the model? Somehow it doesn't seem to bind.
...
5
votes
1answer
809 views
Karma 'Unexpected Request' when testing angular directive, even with ng-html2js
After spending the last day trying to make this work, I've found that I've circled back around to the same error I was having at the beginning:
Error: Unexpected request: GET test-directive.html
I'm ...
0
votes
1answer
734 views
Karma/Jasmine testing custom directive controller
I'm trying to test an AngularJS custom directive with Karma + Jasmine. I found a way to do it checking many references around the web. But the solution doesn't appear to be the correct way. Let's ...
0
votes
1answer
238 views
AngularJS unit test for directive that queries server returns “Unsatisfied requests”
I have a bookmarking app that takes in a url and automatically extracts a summary. When the client requests the server to add a new bookmark, the server sends back some initial information and ...
1
vote
0answers
497 views
Karma unit test angular directives with key event handler
I dove into the world of JavaScript a few weeks ago. I use Angular, and I test my code with Karma and Jasmine. I have an angular directive I'm having trouble testing.
I have an angular directive ...
0
votes
2answers
184 views
How to mock element in an angular directive
I have a very simple directive :
angular.module('myModule',[]).directive('myInputAutofocus', function () {
return {
restrict: 'A',
link: function (scope, element) {
...
0
votes
1answer
116 views
Angular directive test not passing, but works in browser. Suspecting jqlite to be the culprit
I'm trying to test an Angular directive, and I'm not sure why my tests aren't passing. I'd really appreciate a few extra sets of eyes to help me get this figured out.
The directive under test is a ...
1
vote
1answer
304 views
isolateScope() returns undefined when using templateUrl
I have a directive that I want to unittest, but I'm running into the issue that I can't access my isolated scope. Here's the directive:
<my-directive></my-directive>
And the code behind ...
4
votes
1answer
105 views
$digest rendering ng-repeat as a comment
I'm writing a test for a directive, when executing the test the template (which is loaded correctly) is rendered just as <!-- ng-repeat="foo in bar" -->
For starters the relevant parts of the ...
0
votes
1answer
182 views
testing directive, dom manipulation not occurring - Angularjs/jasmine
I am running my first test on a directive, and while it seems that the directive is being invoked (there is a GET request being made for the directive's template url), the DOM manipulation that is ...
2
votes
2answers
95 views
Angular JS directive “@” $scope in-$digestion
Given:
var myApp = angular.module('myApp', []);
myApp.directive('myDirective', function () {
return {
restrict: 'E',
scope: {
classToAdd: '@'
},
...
1
vote
1answer
249 views
Unit Testing private functions in AngularJS Directive
How do I unit test a function that is defined inside a directive like the following myFunc?
angular.module('myApp')
.directive('myDir', [function () {
var myFunc = function (arg) {
// ...
0
votes
1answer
984 views
Unit testing AngularJS Directive with isolated scope - how to get bindings to output?
I'm really needing advice and guidance on testing AngularJS directives with Isolated Scope.
Say I have the following directive (which works):
angular.module('myApp')
.directive('pageNav', ...
1
vote
1answer
1k views
How do I inject a mock dependency into an angular directive with Jasmine on Karma
I have the following directive:
function TopLevelMenuDirective ($userDetails, $configuration) {
return {
restrict:'A',
templateUrl: staticFilesUri + ...
5
votes
2answers
708 views
Testing AngularJS scope variables
I'm trying to implement a test that relies on a scope variable. I want to enable ng-switch-when to resolve an expression. This is what I'm trying to do (UPDATE using $rootScope):
it('should switch on ...
0
votes
0answers
729 views
AngularJs : triggering an event to simulate user action when unit testing a directive
I have seen that in order to simulate user action on the DOM generated by a directive, there are two approaches, both trigering an event:
How to trigger ng-change in directive test in AngularJS
The ...
0
votes
0answers
266 views
Angular-(floating)directive - another angular testing riddle (for a directive that listens to DOM event)
I'm trying to figure out how to unittest a directive like this:
.directive('stFloatBar', function ($log, $window) {
return {
restrict: 'A',
replace: true,
transclude: true,
...
1
vote
1answer
746 views
how to unit-test setInterval in karma angularjs
app.directive('shuffleBlocks', function($timeout){
return {
link: function(sco,ele,att){
if (itemCnt <= 1) return;
/*Trigger function*/
function ...
0
votes
1answer
545 views
Karma testing a directive says angular.element has no method 'hide'
I'm trying to setup Karma to test an angular app that I'm building. I've already setup testing around my services and controllers but am finding directives somewhat more complicated to test.
The ...
5
votes
2answers
1k views
unit test spy on $emit
I'm trying to spy on an $emit from a directive, but somehow I cannot get the spy to 'hear' the $emit.
This is the code in my directives' controller:
$scope.$on('send', function () {
...
0
votes
1answer
420 views
Unit testing an angular directive wrapping slickgrid
I would like to test my angular directive that is a wrapper around slickgrid.
'use strict';
describe('Unit: Grid Directive', function() {
var $scope;
var element;
beforeEach(module('grid'));
...
1
vote
0answers
261 views
cannot use $rootScope.$new() in testing directive
I have a unit test for my directive:
describe('Directive: ov-tabs', function() {
var $compile, scope,subScope, element, template, doc,timeout,window;
...
1
vote
0answers
110 views
ngAnimate interferes with unit tests concerning ngClass in v1.2.0-rc.2 and an aside
I have some unit tests for a directive that worked fine until I migrated to the latest release candidate. The tests pass without incident even under the RC, but fail if the main module includes ...
0
votes
1answer
446 views
Unit testing a directive with <select>
I have a directive called <dimension> that renders html:
angular.module('myApp.directives').
directive('dimension', ['$rootScope', 'Dimension', function($rootScope, Dimension) {
return {
...
1
vote
1answer
210 views
How to test directive which template have ng-include inside the ng-repeat
I write a directive. In the template i have used ng-include inside the ng-repeat:
<div ng-repeat="page in wStepPages" id="step{{$index}}" data-ng-show="getCurrentStep() == $index" ...
0
votes
1answer
248 views
BeforeEach with expectGets cannot be executed more then once
I have a problem with my unit test for a directive where I need to setup the directive before being able to test it.
This is the way I initialize it:
var elm, $templateCache
var count = 0;
...
0
votes
1answer
38 views
Testing angularj facebook login directive
I am creating a Facebook login directive based off this blog.
app.directive('facebook', function($http) {
return {
restrict: 'A',
scope: true,
controller: function($scope, ...