Tagged Questions
0
votes
0answers
11 views
Angular unit testing: $httpBackend.flush() causing $$route be 'undefined'
I am trying to create unit test for server request failure:
Test:
it('should progress $http on error', function () {
httpBackend.whenPOST("/paymentUrl").respond(503);
...
1
vote
0answers
15 views
$httpbackend respond undefined
Trying to get a similar behavior as in Example
UnitTest.coffee:
describe 'Unit: EditAccessController', ->
...
(var $httpBackend, personRequestHandler)
personUrl = /\/people\/\d+/
...
0
votes
0answers
25 views
AngularJS testing: Mocking $httpBackend - Handling Success and Error Methods
Update: I managed to further narrow down the problem scope and fix the Unexpected request error by updating the httpBackend.when request which contained some invalid ascii characters.
I have attached ...
0
votes
0answers
19 views
testing angularJS services that use other services
I'm (slowly) learning how to test my AngularJS app and I've come up against something that I'm struggling to work out.
I have an Auth Service which I'm testing successfully using httpBackend to mock ...
0
votes
0answers
17 views
How can I test angular ui-router $stateChangeStart listeners?
Here's a basic authentication scheme I'm using in angular. I'm trying to unit test this little chunk that listens for state changes and checks both if they need authentication and if the user is ...
0
votes
2answers
14 views
Unit test angular directive that uses ngModel
I am trying to unit test a directive that uses ngModel and having difficulties. It seems that the link function of my directive is never being called...
Here is my directive code:
...
0
votes
0answers
21 views
How to mock self executing service with Jasmine
In an AngularJS app, I'm injecting a 3rd party Factory into a Provider and I'd like to test if that factory has been called using Jasmine.
Here's the provider:
myApp.provider('myProvider', ...
0
votes
0answers
9 views
Element with directive doesn't $compile properly in unit test
My directive runs fine in the browser. It's just the unit test I can't seem to get working. The directive creates a simple slider, and sets a few values on the scope, including min.
In the unit test, ...
1
vote
1answer
25 views
AngularJS - testing when using module approuch
I have a problem with my test set-up. It does work when everything in a single file, it does not when code is spread across multiple files.
When the code is spread as per below, I get an error Error: ...
0
votes
0answers
12 views
unit test angular $event with jasmin
what would be the best way to test this directive function?
$scope.addToToList = function(event){
var offset = $(event.target).offset();
addToListService.showPopUp(offset.left, ...
0
votes
1answer
10 views
How write a Unit-Test For method call after Angular Broadcasting event
I am attempting to test that my controller opens a modal when a broadcast event is fired.
The code works fine but the expectation always fails:
it('should open model on idleStart', function () {
...
0
votes
0answers
23 views
Make $httpBackend ignore any requests made to server
I have the following controller (notice that at instantiation time I make an explicit call to $scope.getNotifications()):
bla.controller("myctrl", [
"$scope", "$http", "configs", function ...
0
votes
1answer
16 views
Protractor waitForAngular() not working for an Async Call
I am working on creating Mock test cases for my application. I don't want to call our Service end-points just for testing, as they have the dedicated tests for them. So, I am mocking the data and ...
0
votes
2answers
31 views
mock a function call using jasmine
Getting started with HotTowelAngular template and I'm setting up unit testing. Ran into a snag.
I'm trying to test a function in my controller that happens to call another function named "log". This ...
0
votes
0answers
20 views
Why won't my AngularJS Spy function get called?
My controller is:
webApp.controller 'AboutUsController', [
'$scope'
'$rootScope'
($scope, $rootScope) ->
$scope.init = ->
console.log 'About Us Page'
$scope.init()
]
And ...
0
votes
0answers
18 views
Karma: ReferenceError: app is not defined
I followed the tutorial from http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html for testing AngularJS apps with Karma.
My karma.conf.js looks like this:
...
0
votes
2answers
24 views
Jasmine mocking a constructor within a function
I get an error when running Jasmine tests: 'ReferenceError: JSZip is not defined'. Here's my controller:
$scope.makeZip = function() {
var zip = new JSZip();
zip.file('myPhoto.txt', 'Hello ...
1
vote
0answers
57 views
unit testing angular directives templateUrl (include requirejs and ng-html2js
I am working on a not-yet-huge angular app. I have got a problem with karma unit testing. To make a long story short, I am using angular with requirej. My tests run well if I keep my template embedded ...
1
vote
0answers
23 views
Angularjs testing D3 directive compile bug
I have an angularjs directive containing some D3 code. This directive works perfectly when used in the application. My problem occurs when I compile this directive for test purposes, a part of the ...
1
vote
1answer
35 views
AngularJS + CanvasJS: how to unit test?
I'm tring to run unit tests in an AngularJS application scaffolded using Yeoman.
The only test I'm trying to run just check if and array has correct length but fails
because of something related to ...
0
votes
1answer
26 views
How to mock angular translate filter in unit tests for directives
In my directive templates, I need to use the angular translate filter as such:
<label for="data-source-btn">
<span id="data-source-btn-span"></span>
{{'Data Source' ...
0
votes
1answer
35 views
AngularJS Unit testing with Restangular - nested promises
I'm testing my directive which used Restangular for some API calls in the controller.
For functions with promises used by Restangular I'm mocking those functions and putting together with my main ...
0
votes
0answers
16 views
Jasmine - Handling global variable which holds server side informations
I am a newbie to Jasmine. I have developed a single page application using Angular JS in Salesforce CRM platform. I have a global variable in the head tag, which contains some server side information ...
0
votes
1answer
25 views
How to actually reset $httpBackend expectations?
I've tried and tried to get this to work. The documentation is terse, at best:
resetExpectations(); - Resets all request expectations, but preserves all backend definitions. Typically, you would ...
0
votes
1answer
26 views
Cordova & AngularJS unit testing
I'm currently developing an application based on Cordova (http://cordova.apache.org), deployed on iOS for now.
I've started to write some unit tests using jasmine, as i used to do when i developed a ...
0
votes
0answers
10 views
object and resource comparison error when doing http.get request
I'm confused as how to fix this problem. I'm mocking a http.get request from my service and in my unit test the resource returns identically the same contents as the expected result, except that the ...
0
votes
1answer
47 views
spyOn $scope.$on after $broadcast toHaveBeenCalled fails
I'm having a lot of trouble getting this simple test working.
I've got an $scope.$on listener in a controller that I want to test. I just want to make certain it's called after a broadcast event.
To ...
0
votes
1answer
31 views
AngularJS unit testing directive with ngModel
I have made a directive which uses ngModel:
.directive('datetimepicker', function () {
return {
restrict: 'E',
require: ['datetimepicker', '?^ngModel'],
controller: ...
1
vote
1answer
44 views
How to test if the scope is populated after the broadcast and evaluating URL redirection process?
Updated : In this controller I am trying to test the user login process and it calls loginRequest method in WebService to send out user credentials as a login message. A loginreply message is received ...
0
votes
1answer
43 views
AngularJS controller unit test using the “controller as” syntax
I'm having some trouble adapting this test to use the "controller as" syntax. Here's what I have ...
The controller I'm testing is:
function MyCtrl ($scope, someService) {
someService.get()
...
0
votes
1answer
31 views
$rootScope is undefined when testing with Karma
I am trying to write some unit tests for an angular project. I've followed some examples about testing a controller but I always end up with the same problem: $rootScope seems to be undefined.
My ...
0
votes
2answers
25 views
$scope.$on undefined in controller during unit testing
My controller works great. But when I want to test it in karma the $scope.on method comes up as undefined.
Here is my controller:
angular.module('myApp').controller('DataController', [
...
0
votes
1answer
13 views
$httpBackend mock not sending a request?
After too many hours, I cannot for the life of me get this example working. I'm following Ben Lesh's excellent guides to mocking $http requests in Angular, but for some reason the service request is ...
3
votes
1answer
64 views
AngularJS Change Constant Value that gets passed to Config for Unit Test
Is there anyway to change the constant value that gets sent to the config function of the module for a Unit Test?
I have the following (fiddle here):
//--- CODE --------------------------
var module ...
-1
votes
0answers
21 views
how to get jasmine test working?
Just started trying jasmine unittesting and angularjs.
I am getting a reference error:
ReferenceError: browser is not defined in http://run.plnkr.co/spLhS7TjY5NO1w78/appSpec.js (line 11)
the ...
3
votes
1answer
41 views
Protractor E2E - How Do You Manage Database?
I'm currently leaning on the Node + Angular stack and utilising Karma and Protractor for testing.
I'm currently having a hard time figuring out how to handle E2E tests that create and edit data, as ...
0
votes
1answer
37 views
Jasmine 2.0 async done() and angular-mocks inject() in same test it()
My usual test case looks like
it("should send get request", inject(function(someServices) {
//some test
}));
And Jasmine 2.0 async test should look like
it("should send get request", ...
0
votes
0answers
20 views
AngularJS unit testing error when using clientWidth
In my code there's a line:
var contentWidth = angular.element(document.querySelector('.content'))[0].clientWidth;
It works fine when running the app but when unit testing I get error:
TypeError: ...
0
votes
1answer
33 views
Unit-testing slider directive with AngularJS + Jasmine
I am a newbie to both Angularjs and unit-testing with jasmine, so iI hope this makes sense and is correct enough to get an answer :)
I am trying to test an angularJS directive that creates sliders ...
0
votes
0answers
16 views
Expected spy to be called error at null<anonymous>
i'm totally lost on what to do. I have googled all possible ideas to test if my method was called, but no luck so far. All i want to do is check if my method has been called.
this is my test script
...
0
votes
1answer
29 views
how to test $scope.method inside a controller?
I've tried using Spies, tried declaring a variable by calling the function and nothing works.I 'm new to unit testing and i must be misunderstanding something
my unit test for the function
...
0
votes
1answer
22 views
how to check if methods have been called jasmine unit test
I'm new to unit testing, and after reading the docs I'm still confused on how to do checks on asynchronous methods, as far as i understand I will need to use runs() and wait(). However, instead of ...
0
votes
1answer
92 views
Inject AngularJs service used in run closure for testing
I am trying to test an angularjs service called MyService. If I try to inject it, seems that angular tries to use it before is loaded. On the other hand, if I mock MyService via $provide and so on, ...
0
votes
1answer
24 views
karma.conf.js uncaught referencerror: google no defined
when i try running the karma test runner, i'm getting a error as the following from one of my files, saying that my library google is undefined???
Chrome 36.0.1985 (Mac OS X 10.9.4) ERROR
...
1
vote
1answer
43 views
karma unit test runner directory injector error
So in my app.module, i have some injectors that are actually directories that store html element directives for templates. The problem is that karma is complaining that the directories are not ...
0
votes
1answer
48 views
Unable to bind my fake array to a scope variable in my test
I'm unable to bind my fake array to a scope variable in my directive test.
My test:
describe('Directive: report - section', function () {
// load the directive's module
...
1
vote
0answers
46 views
karma test runner error: require jquery
I'm new to using karma and unit testing in general. I tried finding a solution by googling this problem, but I wasnt able to find anything useful , as my app/assets/components does not have any jquery ...
1
vote
1answer
20 views
How to change $httpBackend when[method] statements between requests in unit testing?
In my testing i initiate some model data and mock the response:
beforeEach(function(){
var re = new RegExp(/^http\:\/\/.+?\/users-online\/(.+)$/);
$httpBackend.whenGET(re).respond({id:12345, ...
0
votes
1answer
35 views
karma test runner not running any tests
I'm using karma with jasmine and followed online guide by installing using
npm install --save-dev karma
and other necessities
i ran
./node_modules/karma/bin/karma start
and
karma start ...
-1
votes
1answer
17 views
Should I write unit-tests for 'wrapper' methods
I have function in controller of my directive:
$scope.getPossibleWin = function() {
return betslipService.getPossibleWin()
}
betslipService injected into controller
Now I'm thinking how to ...