Tagged Questions
-3
votes
0answers
19 views
How to write unit test cases for “Factory” in angularjs
How to write unit test cases for "Factory" in angularjs?
number.factory('nativeService', function($rootScope, syncservice){
Interface.setAuthInfo = function (data, info, expiry){
...
0
votes
2answers
9 views
AngularJS testing with Jasmine unable to call “angular.mock.module” while using angular-mocks.js
I'm trying to get a basic unit test working and am running into an issue using angular-mocks.js. Hopefully this code will explain my situation.
describe("peconfigApp", function () {
...
0
votes
1answer
29 views
Is it standard behavior to assign singleton variables (used only in unit testing) in a controller?
"myEvent" is fired when clicking on any div in a grid,
watching this event using:
$scope.$on('myEvent', function (e, info) {
var someString = someStringHelper.convertToString(info);
...
0
votes
1answer
22 views
Jasmine + AngularJS unit test a rest call
I am trying to write some tests for my rest calls and I am trying to figure out how to make a unique rest call per it declaration. For example:
describe('My testing',function()
{
var $scope;
...
1
vote
0answers
17 views
angularjs controller test failed
I am struggle up to write a simple angularjs controller testcase by angular-mock and jasmine.
I am using angularjs v1.0.8 and jasmine 1.3.0.
My code is like this:
1. demoController.js
'use ...
1
vote
0answers
76 views
Angular JS - Getting [$resource:badcfg] error when unit testing $resource.get but is fine on controller
Here's how I setup my Article resource:
define(['services/index', 'services/Helpers'], function(services) {
'use strict';
services.factory('Article', ['$http', '$resource', 'AppConfig',
...
0
votes
0answers
31 views
angularjs: how to mock $rootScope in unit test
I have a unit test that looks like this
describe('Interceptor: myInterceptor', inject(function($rootScope){
var rootScope, routeParams = { id: null };
beforeEach(module('MyApp', function ...
0
votes
0answers
53 views
Unit test of $cacheFactory removeAll() in service failing in Angular 1.2.0 but working in 1.0.7
I have a unit test for an Angular service in which I test that a cache $cacheFactory is cleared after a call has been made for a save() method that does an http post to the backend. In 1.0.7 this test ...
4
votes
0answers
50 views
Angularjs - how to correctly replace service dependency with a mock
I'm using yeoman generator created app, and doing my tests in karma.
I have reusable mock objects for every of my service.
How do i correctly replace specific service dependcy with a mock, so i could ...
1
vote
1answer
53 views
Angularjs Jasmine Test: Making api call with $backend
I have run into an issue, that after at least 8 hours of searching and tinkering and coming up empty handed requires some help from the community. There are articles that attempt to address similar ...
0
votes
1answer
21 views
How to trigger $emit to test $on listener in a controller when testing it with Jasmine?
I've got a controller and want to test it with a Jasmine. There is an $on listener in the scope of controller that I want to test. How do I trigger $emit event to run $on listener?
...
0
votes
0answers
37 views
AngularJS controller unit testing with $http.get() on load
I'm having difficulties understanding how to resolve the problem of the unit testing the controller, which makes a GET call during initialisation.
When testing the controller method, that performs ...
0
votes
1answer
20 views
Angular Unit Testing a resource request
I am attempting to perform a unit test on this controller.
angular.module('app.dashboard', [])
.controller('DashboardController', ['$scope', 'myAppService'], function($scope, myAppService) {
var ...
0
votes
0answers
27 views
How can I mock an http call executed in module.run Angular app?
I am trying to run the following code (where fusseApp is an angularModule) :
<code>
fusseApp.run(function(URI, $http){
$http.get('/check/userLogged').then(function(response){
...
1
vote
1answer
29 views
AngularJS and Virtual Paths
How do you deal with Virtual Paths in AngularJS?
For example in my test environment, my base url is http://localhost/AppName/ and in production the root becomes http://www.mysite.com/.
So in dev, a ...
0
votes
1answer
39 views
angularjs unit test controller orderBy
I have problem to write a unit test for my controller which test orderBy in the table with elements.
I have advert.html:
<body ng-app="motoAdsApp" ng-controller="AdvertsController">
...
0
votes
2answers
67 views
angularJS: unit tests gives: Unknown provider: $httpProviderProvider <- $httpProvider
In one of my unit tests I'm trying to do
beforeEach(function () {
angular.mock.inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
mockUserResource = ...
0
votes
0answers
59 views
Correct way to mock an AngularJS Service in a unit test?
I have the following controller and service that I am trying to write tests around in Jasmine. I am fairly new to this, and just wanted to see if I am taking the correct approach in testing and ...
4
votes
1answer
109 views
AngularJS / Karma unit testing with real XHR data / passThrough()
I would like to use real $http data for my unit test using passThrough().
Here's what I have so far:
var should = chai.should();
beforeEach(module('myApp', 'ngMockE2E'));
...
1
vote
1answer
88 views
Unit Testing AngularJS Service
I am trying to figure out how to test my AngularJS service that has a dependency on $http.
When using $httpBackend to mock that AJAX post (whenPOST), does the object you post determine the response?
...
0
votes
2answers
56 views
AngularJS : Stubbing JQlite methods
I'd like to unit test some logic in my directive :
...
link: function ($scope, $element) {
var rightMargin = 3;
var w = $element.find('span')[0].scrollWidth;
if (w > 100) {
...
0
votes
1answer
20 views
Difference between “angualar.module” and “module” when unit-testing Angular
What is the difference between angual.module('app') and module('app')?
Here is the simple service and unit test in question:
Service
(function () {
"use strict"
var app = ...
1
vote
1answer
45 views
how to test with custom dom event in angularjs
I have written custom events for mobile devices in jasmine,
and I am trying to fire the events.
so instead of
angular.element()[0].click()
how may I trigger custom events and other events to ...
1
vote
1answer
56 views
Testing an Angular Promise with Jasmine
The following test keeps failing and I can't figure out why? I am trying to figure out how to test defereds/promises with Jasmine.
Error
Expected undefined to be 'Resolved Data'.
Test
...
2
votes
1answer
76 views
Unit testing AngularJS and Flot Charts
I am trying to unit test (Jasmine) AngularJS and Flot Charts but receive the following errors. I do not receive these errors in the console of my application and the charts render as expected.
...
1
vote
1answer
58 views
AngularJS with Jasmime, nested services test
After reading so many posts on AngularJS testing with Jasmine, I came to the conclusion that the way I built my service is not a testable one.
But still, I'm too much of a noob on AngularJS to really ...
0
votes
1answer
32 views
angularjs jasmine testng - How do I mock a resource for a factory
I can succesfully mock a resource for a controller, but I am unsure how to do so for a factory.
beforeEach(inject(function ($injector) {
$scope = $injector.get('$scope');
$controller = ...
1
vote
0answers
40 views
angular unit test - error instantiating controller
I am trying to configure basic unit tests for the controller "CardDetailCtrl", but it fails, with this error on the console :
"Argument 'CardDetailCtrl' is not a function, got undefined'"
I'm sure I ...
0
votes
0answers
35 views
Testing Angular JS Directives with URL Templates with Chutzpah
I have the following directive that I need to put some unit tests around.
treeApp.directive('treeContent', ['contentService', 'factsService', 'sourceDeleteManager', function (contentService, ...
0
votes
0answers
69 views
AngularJS, Jasmine, Chutzpah… Unit testing a filter?
I am just trying to get a better understanding of Jasmine unit tests with AngularJS. So I setup a test around an existing experimental project I started. I'll just start off with the code, my question ...
0
votes
1answer
37 views
how to mock a location.path in angular unit tests
http://blog.artlogic.com/2013/05/06/angularjs-best-practices-ive-been-doing-it-wrong-part-2-of-3/
I am testing a routing directive with location.path refs to templates that cannot be found. So....
I ...
0
votes
0answers
23 views
using Angular Scenario to test Vagrant application
I have installed karma for js unit testing and angular scenario and works fine with statics, but how to make it work with my Vagrant app?
i am getting some errors regarding the protocols (switched ...
0
votes
1answer
122 views
Error: Argument 'MainCtrl' is not a function, got undefined
I've just installed Yeoman and created my first project. I'm trying to get my head around unit testing the default angular project that is created by Yo. The project runs fine when I invoke "grunt ...
0
votes
0answers
21 views
Writing test to verify that decorator calls delegate
I'd like to write a test that verifies my decorator is being a good citizen by calling the injected delegate.
For example, let's say I want to decorate the $log service to prefix the message.
...
0
votes
2answers
82 views
Error: No pending request to flush !: How can I verify that $httpBackend is being used in jasmine unit tests?
I am trying to write a unit test for a service that I have written that uses $http
I keep getting
No pending request to flush !
I have followed 2 or 3 examples and no matter what I change I keep ...
0
votes
1answer
39 views
how to test routing in angularjs
app.directive('ngRef', function($location, $timeout){
linkFn = function(sco,ele,att){
ele.bind('click', function(){
// console.log($location);
$timeout(function(){
...
0
votes
1answer
51 views
how to mock a scope from a directive instead of a controller in angular unit-test
so i am familiar with the concept of mocking a $scope and controller with a $controller constructor
var scope = rootScope.$new();
it('should contain a testVar value at "test var home"', function(){
...
0
votes
1answer
53 views
How to clean cache before $httpBackend.flush() in AngularJs Unit Test?
I need to make unit test for a directive in my Angular project. This directive refer a service which use $http required get data and then store them in local cache. and my test case like this:
...
0
votes
1answer
53 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 fuction*/
function ...
0
votes
0answers
20 views
Call httpBackend with same arguments but return different values
I have a unit test where I am checking that a service polls a URL using $http. The first time round I want to return a value that will cause the service wait 10 seconds (using $timeout) and then to ...
0
votes
1answer
60 views
how does timeout work in angular tests running in karma
I love using console log for feedback perhaps too much, and sometimes I run into code that as convention we've added $timeout in the directive/service/controller, sometimes as long as 500 ms, and now ...
0
votes
1answer
31 views
how to correctly write angular unit-tests against routing
So I have a directive that mimiks the href function except i wanted it to be doable with buttons, (say i dont like to css a tags).
app.directive('ngRef', function($location, $timeout){
linkFn = ...
0
votes
0answers
56 views
Why do promises.then() and $httpBackend.flush() in AngularJS not behave as expected?
I'm using Jasmine to write some AngularJS unit tests. Here is some sample code:
var processResult;
beforeEach(inject(function ($injector) {
var httpBackend = $injector.get('$httpBackend');
...
0
votes
2answers
74 views
test of angularjs controller: unsatistifed post request
I'm testing an angularjs controller, using also mocks, but it raises the error 'Error: Unsatisfied requests: POST /myurl
My file for test contains a beforeEach method like this
...
0
votes
1answer
27 views
What is the bare minimum installation suite for unit testing in AngularJS?
I'm attempting to learn AngularJS. One of the things that attracts me is its claim of separation of concerns and unit testability. So it defeats me completely to understand why I should need to ...
2
votes
2answers
96 views
Mock out angular.element in Jasmin tests
I have a function in a controller that has a call
var someVar = angular.element(event.target).scope().field;
I am trying to mock it by doing
var ngElementFake = function(el) {
...
0
votes
0answers
39 views
How to let an angular $http call time out in an unit test?
How to make an AngularJS $http call time out in an unit test so I can test my code behavior in case of network timeouts? I've found nothing in $httpBackend object, also experimenting with $timeout ...
0
votes
1answer
66 views
How do I test $scope.$on in AngularJS
How do I test that the scope is populated after the broadcast? I've searched and found a few QA's here in stackexchange, but none answered my problem. The code is working alright, just don't know how ...
0
votes
1answer
24 views
in angular web application what needs to be unit tested?
for a front-end developer, who writes angular code, what part of a javascript front-end project should I be unit testing? I find it needless to test a lot of the code, and my biggest hang up is which ...
2
votes
1answer
141 views
Unit testing a directive whose templates are all one with file with script tags
I am having a hard time figuring out how to include my directive's templates (that are all in one file in different script tags) in my Karma unit tests.
The error I get:
PhantomJS 1.9 (Linux) ERROR
...