All Questions
Tagged with angularjs-controller unit-testing
18
questions
25
votes
1answer
37k views
Karma testing: TypeError: Attempted to assign to readonly property
When I am trying to unit test my controller I am getting the error.When I debug the testcase's expect I am getting the expected value but its failing with below error.What am I missing here or whether ...
9
votes
2answers
10k views
Mocking the event object in AngularJS event unit testing
I have the following test:
it('Should keep location when user rejects confirmation', inject(function ($controller, $rootScope) {
var confirmStub = sinon.stub(),
eventStub = {
...
6
votes
1answer
15k views
how to return rejected/failure promise to through jasmine spy to an angular controller in a unit test
I am using jasmine for testing my angular controllers.
I am catching errors and success in the .then(successCallback, errorCallback)
Although it is working fine on the bases of live functionality but ...
3
votes
3answers
3k views
How to test response from service within controller
I am trying to test the response from a service http call that is performed within a controller:
Controller:
define(['module'], function (module) {
'use strict';
var MyController = function ...
2
votes
1answer
947 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 ...
2
votes
1answer
771 views
Unit test angularjs controller
I've been looking through countless SO post on this but can't get the unit test of my angular controller to work.
Error:
TypeError: Object #<Object> has no method 'apply'
Error: [ng:areq] ...
2
votes
1answer
608 views
Unit Test Angular Controller Init Code?
I have a service that is invoked first thing by a controller. I can't figure out a way to test it with jasmine 1.3.
I cant spy on the productService instance 'fetch' method because by the time the ...
1
vote
1answer
188 views
Angular Unit Testing: Isolate certain components defined on module
I've inherited a large AngularJS project using Karma and Jasmine and am trying to follow the conventions that were set out before me, but am having trouble unit testing directive/controller modules. ...
1
vote
1answer
660 views
Unit-Testing a service in Controller with Jasmine in AngularJS
In my Controller I've defined the following service:
CrudService.getAllGroups().$promise.then(
function (response) { $scope.groups = response; },
function (error) { //error code.. }
);
Well, ...
1
vote
2answers
1k views
Angular controller test on scope.variable is undefined
I'm trying to learn angular unit test with $resource.
Here I have a simple controller :
.controller('DictionaryCtrl', function ($scope, DictionaryService) {
$scope.jSearchDictionary = function () ...
1
vote
1answer
642 views
How to test a directive which uses ngModel on same element
I have a directive which requires ngModel. In its link function it calls $setViewValue on the ngModel controller. I want to test that $setViewValue is being called under the right conditions, but I ...
0
votes
1answer
400 views
Jasmine AngularJs How to access Controller's properties
This is my AngularJs code, I would like to write a unit test which should call variables and functions inside the controller function.
For example, I would like to expect whether the abcCode is ...
0
votes
1answer
470 views
How to test angularjs controller async behavior without using Timeout
So I have a controller like this:
angular.module('someModule').controller('someController',function(productService) {
$scope.products = [];
$scope.init = function() {
aService.fetchAll()....
0
votes
0answers
73 views
What happens when you do not use $destroy() after creating an instance using $new() when unit testing AngularJS
I was looking for ways to unit test AngularJs when using the "controller as vm" style. I came across this (Karma jasmine and angular controller using 'Controller as' syntax (this instead of $...
0
votes
1answer
231 views
Mock Service Within Controller Returning Undefined
I am trying to test something pretty simple: a controller that calls a service that performs a http request.
Controller:
define(['module'], function (module) {
'use strict';
var ...
0
votes
2answers
842 views
AngularJS - unit testing a controller method that gets called on initialization
In my AngularJS Controller, I have a $scope.init method that gets called when the controller gets initialized. $scope.init calls $scope.loadData and $scope.loadNames, which each fire an HTTP GET ...
0
votes
0answers
53 views
Unit testing controller triggering custom directive
Suppose you have an angular+jasmine app and your controller looks something like this:
app.controller('MyController', function($scope) {
$scope.myFunc = function() {
$scope.myArray = [];
...
0
votes
0answers
196 views
How do I properly initialize/mock and unit test input data in a directive's externally-defined controller?
I have a custom directive that uses an external controller and template. The user passes in some initial data to the directive, which is used inside the controller.
When I'm unit testing ...