Issue I would like to inject this function into the ng-init directive when I instantiate a controller in an angular test, in the html I would set it up like this: <div ng-controller=”my-ctrl” ng-init=”initialize({updateUrl: ‘list_json’}) In my test I could
Continue readingTag: angular-mock
AngularJS, how to extract mock dependency injection like ngMock
Issue We have an analytics service which is dependency injected to most of our controllers to help us track actions users make. Rather than going through setting up the mock version of this service every time a test suite is
Continue readingInject $log service on simple Jasmine test
Issue Yes, I’m completely new to Angular and Jasmine, and I can’t figure out how to inject a mock $log for my test. This is the test: (function () { ‘use strict’; describe(‘basic test’, function(){ it(‘should just work’, function(){ var
Continue readingAngularJS $httpBackend expectGET not working
Issue I am writing QUnit tests for an AngularJS factory. Here’s the code for the factory: var app = angular.module(‘App’, []); app.factory(‘$groupFactory’, function($rootScope, $http) { return { ‘getAll’: function(_callback) { $http.get(“get/values/from/server”, { headers: { ‘Content-type’: ‘application/json’ } }).success(function(data, status, headers,
Continue readingUnit Testing AngularJS and PouchDB Service
Issue I am attempting to unit test my individual Angular factories but am having a hard time trying to correctly mock and inject the PouchDB object. My factory code is currently as follows: factory(‘Track’, [function() { var db = new
Continue readingAngular mock fails to inject my module dependencies
Issue I want to test an Angular controller for my application fooApp, defined as follow: var fooApp = angular.module(‘fooApp’, [ ‘ngRoute’, ‘ngAnimate’, ‘hmTouchEvents’ ]); … The controller, MainCtrl is defined: “use strict”; fooApp.controller(‘MainCtrl’, function ($scope, $rootScope, fooService) { … }
Continue readingCreate unit tests where each test has its specific test data and test mocks
Issue I have this test structure and it is working but It does not cover my requirements when I put more tests in this unit test .js file , but all related tests should go there. WORKING: ‘use strict’; describe(‘lessonplannerFactory
Continue readingAngularJS Mock Self Executing Controller
Issue How do I prevent an angular controller with a self instantiating function from executing for tests? (I have used a contrived example to illustrate my issue) I have a controller that executes some code on startup (in my case
Continue readingangular resource promise catch, jasmine toThrow()
Issue I have some code in an angular controller: user is an angular $resource which returns a promise when the get method is called. $scope.credentials = { username:””, password:””, rememberMe:false }; var currentUser = {}; $scope.login = function(callback){ user.get($scope.credentials) .$promise
Continue readingAngular.mock.$interval.flush() throws strange exception
Issue I have created the following small controller for testing that the interval function is triggered at the specified interval angular.module(‘app’).controller(‘myTstController’, [ ‘$interval’, function($interval) { var called = 0; $interval(function() { called++; }, 10); this.getCalled = function() { return called;
Continue readingHow do I mock $window injected manually in provider private function?
Issue I have the following provider: angular.module(‘MyApp’).provider(‘MyDevice’, function () { var ngInjector = angular.injector([‘ng’]), $window = ngInjector.get(‘$window’); function isMobileDevice () { return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/) .test($window.navigator.userAgent || $window.navigator.vendor || $window.opera); } this.$get = function () { return { isDesktop: function ()
Continue readingHow to Jasmine test code within angular module run block
Issue I would like to Jasmine test that Welcome.go has been called. Welcome is an angular service. angular.module(‘welcome’,[]) .run(function(Welcome) { Welcome.go(); }); This is my test so far: describe(‘module: welcome’, function () { beforeEach(module(‘welcome’)); var Welcome; beforeEach(inject(function(_Welcome_) { Welcome =
Continue readingHow to inject an entire module dynamically in AngularJS?
Issue Alright, so I’m trying to set-up $httpBackend to use as a mock server for local development against an API. I have two services in separate modules: search and searchMock: search returns a $resource object that exposes the API verbs
Continue readingkarma/jasmine/angular toHaveBeenCalledWith is really called
Issue in my app for instance I’ve got $rootScope.$emit(‘loggedin’,data.user); $rootScope.$on(‘loggedin’, function(event,user) { console.log(‘called’); }); in my test spyOn($rootScope, ‘$emit’); var response = { “success”:1, “user”:{ “id”:1, “email”:”lama@test.test”, “fullname”:”Lama user”, “username”:”lamauser”, “groups”:[“Users”] }, “logged”:1 }; $httpBackend.when(‘POST’, ‘/api/v1/user’).respond(200,response); $scope.save(); $httpBackend.flush(); expect($scope.errors.length).toEqual(0); expect($rootScope.$emit).toHaveBeenCalledWith(‘loggedin’,response.user);
Continue readingkarma/angularjs how to test run block with service
Issue This post follow this I’ve posted an other thread with a easier example code to test ‘use strict’; var app = angular.module(‘myApp’, []); app.run(function ($rootScope, Menus) { var menus = [ { ‘permission’: null, ‘title’: ‘Home’, ‘link’: ‘home’ },
Continue readingkarma/angularjs how to test run block with an asynchronous service
Issue How can I test like: init.js lama.system module angular.module(‘lama.system’, []) .config([‘$httpProvider’, function($httpProvider) { // Crossdomain requests not allowed if you want do cors request see filter.php $httpProvider.defaults.headers.common[‘X-Requested-With’] = ‘XMLHttpRequest’; }]) .run([‘$rootScope’, ‘$state’, ‘$log’, ‘Global’,function ($rootScope, $state, $log, Global) {
Continue readingAngularJS – interval doesn't get flushed
Issue I have the angular service function that I am willing to test: doSomeTask: function (ids, callback) { $http.put(‘/get_job’, {‘ids’: ids}).success(function (data) { var statusCheck = $interval(function() { $http.get(‘check_status?=’ + data.job_id).success(function (data) { if(data.completed) { $interval.cancel(statusCheck); // and do something…
Continue readingangular, karma dependency injection, inject failing
Issue So, I’m trying to get to grips with testing angular, and I’m a bit stuck… From what I’ve read (or what I’ve understood from what I’ve read) the below should work, but I’m getting the following error: Error: [ng:areq]
Continue readingangular, karma dependency injection, inject failing
Issue So, I’m trying to get to grips with testing angular, and I’m a bit stuck… From what I’ve read (or what I’ve understood from what I’ve read) the below should work, but I’m getting the following error: Error: [ng:areq]
Continue readingangular, karma dependency injection, inject failing
Issue So, I’m trying to get to grips with testing angular, and I’m a bit stuck… From what I’ve read (or what I’ve understood from what I’ve read) the below should work, but I’m getting the following error: Error: [ng:areq]
Continue readingAngular-mocks error instantiating $rootScope
Issue I have a very simple Mocha test (a copy of code that I have seen dozens of times) When I run it, angular mocks appears to successfully load the injected resources and all their dependencies and successfully makes it
Continue readingAngular-mocks error instantiating $rootScope
Issue I have a very simple Mocha test (a copy of code that I have seen dozens of times) When I run it, angular mocks appears to successfully load the injected resources and all their dependencies and successfully makes it
Continue readingAngular-mocks $injector doesn't return service, no $get method
Issue I am attempting to do my best at bdd with Karma and Mocha. I have created this shell of a service to try to get things going (generated from TypeScript) I have created the following test I put a
Continue readingAngular-mocks $injector doesn't return service, no $get method
Issue I am attempting to do my best at bdd with Karma and Mocha. I have created this shell of a service to try to get things going (generated from TypeScript) I have created the following test I put a
Continue readingError: [$injector:unpr] Unknown provider: $$rAFProvider
Issue Using Karma to test Angular getting error: Error: [$injector:modulerr] Failed to instantiate module ngMock due to: Error: [$injector:unpr] Unknown provider: $$rAFProvider Angular mock, Angular versions error? I’ve heard solutions detailing changing of angular-mock version or angular version–which seems like
Continue readingAngular unit test for adding up values
Issue I’m new to angular unit test cases and I’m trying to write a unit test case for the following code that I have in my Angular controller. Data contains balance which is added up and assigned to $scope.Total .success(function
Continue readingunit testing angular issue with window location assign
Issue In my ctrl, I have this code to navigate to a page after the function has completed its work. $scope.myFunction = function(){ //other code window.location.assign(url); } My test code looks like this. describe(‘TEST’, function () { var window; beforeEach(module(function($provide)
Continue reading$httpBackend does not mock $.ajax(…) calls
Issue Trying to create a mock for $.ajax calls using $httpBackend. The below mocking snippet worked fine for worked fine with $http.get(‘/phones’) $httpBackend.whenGET(‘/phones’) But when tried to use the same for $.ajax({ url: ‘/phones’, type: ‘GET’ }) This threw a
Continue readingHow to mock socket.io with Angular and Jasmine
Issue I’m having trouble figuring out how to correctly mock Socket.io in an Angular application using Jasmine and Karma. Here are the files found in karma.conf.js: ‘bower_components/angular/angular.js’, ‘bower_components/angular-mocks/angular-mocks.js’, ‘bower_components/angular-ui-router/release/angular-ui-router.js’, ‘bower_components/angular-socket-io/socket.js’, ‘bower_components/socket.io-client/socket.io.js’, ‘bower_components/angular-socket-io/mock/socket-io.js’, ‘public/javascripts/*.js’, ‘ng_tests/**/*.js’, ‘ng_tests/stateMock.js’ Here is how my controller
Continue readingJasmine/Angular: TypeError: Cannot read property '$modules/$injector' of undefined
Issue I am trying to run jasmine test cases and i am landing on ‘$modules’ of undefined. I am loading unminified and latest versions of libraries as below, <script src=”lib/jquery-2.1.3.js”></script> <script src=”lib/jasmine-2.1.3.js”></script> <script src=”lib/jasmine-html.js”></script> <script src=”lib/boot.js”></script> <script src=”lib/angular-1.3.9.js”></script> <script src=”lib/angular-mocks-1.0.1.js”></script>
Continue readingJasmine – Testing if Controller Exists Getting Error
Issue i have a simple controller: app.controller(“RegisterController”, function ($scope, $location) { // Do something }); And all i am trying to do is to test this controller is defined: describe(‘RegisterController’, function() { var $rootScope, $scope, $controller; beforeEach(module(‘myApp’)); beforeEach(inject(function(_$rootScope_, _$controller_){ $rootScope
Continue readingMatch all GET url using angular-mocks for backendless
Issue I am writing a frontend without backend ajax for now. I am using angular-mocks to simulate API call like this: $httpBackend.when(‘GET’, ‘/somelink’).respond(function(method, url, data) { //do something }); However, if the ajax passes params: {id:12345}, it will append to
Continue readingAngularJS and Jasmine: mocking services
Issue I am having trouble mocking the dependency of the following service “broadcaster” over the service “pushServices”. angular.module(‘broadcaster’, [‘pushServices’]); angular.module(‘broadcaster’).service(‘broadcaster’, [ ‘$rootScope’, ‘$log’, ‘satnetPush’, function ($rootScope, $log, satnetPush) { // .. contents .. }; }; The Jasmine spec is as
Continue readingUnable to get Mocha and Angular mocks to work in Plunker
Issue I am trying to show an example of mocha in plunker but it is giving me angular mocks undefined issues. I tried copy and pasting bower angular mocks to no avail. beforeEach(function(){ angular.mock.module(‘plunker’); }); Errored code from angular-mocks says
Continue readingAngular unit testing error: Error: [$injector:modulerr]
Issue I’m using angular 1.2.2, and angular mock 1.3.5. It’s pretty simple testing code to test my own customized service. angular.module(‘factories’, []) .factory(‘chimp’, [‘$log’, function($log) { return { ook: function() { $log.warn(‘Ook.’); } }; }]); describe(‘factories’, function() { var chimp;
Continue readingIs it possible for jasmine to access the scope methods defined in an angular directive controller?
Issue I’m trying to unit test a directive like the one below. I want to be able to call the functions defined in the directive’s controller ($scope.save), but my tests can’t seem to access that scope at all. I also
Continue readingngMockE2E is causing every request mock the moment added to dependency
Issue I have angular.module(“myModule”, [ //Some dependency “ngMockE2E” ]) This is actually mocking template request and throwing error Unexpected request: GET javascripts/custom/utils/templates/global_loader.html No more request expected at $httpBackend (angular-mocks.js?e_a_v=5:1226) at sendReq (angular.js?e_a_v=5:10215) at $get.serverRequest (angular.js?e_a_v=5:9927) at processQueue (angular.js?e_a_v=5:14437) at angular.js?e_a_v=5:14453
Continue readingAngular Mocks install ask me for dependencies
Issue Sincerely I don’t know what to answer … I’m newbie in Ionic + Angular … I’m trying to install Angular Mocks but it says about Angular version. $ sudo bower install angular-mocks –allow-root bower angular-mocks#* cached git://github.com/angular/bower-angular-mocks.git#1.4.1 bower angular-mocks#*
Continue readingHow to check if location is changed and controller loaded
Issue I’m trying to write a unit test for a controller that does a POST then changes page. How can I check if a path is loaded and the controller for that path is loaded? Solution You can’t check that
Continue readingHow do I test a decorator which is a wrapper around $timeout?
Issue I have the following decorator which wraps around the original $timeout from within $rootScope. When used inside controllers, it will help by canceling the $timeout promise when the scope is destroyed. angular.module(‘MyApp’).config([‘$provide’, function ($provide) { $provide.decorator(‘$rootScope’, [‘$delegate’, function ($delegate)
Continue readingTesting Initialization of AngularJS Service with Mocks
Issue I am trying to test the way an angular service responds to the values it gets from another service when it is initialized, and I’m having trouble finding a non-clunky way of doing it… much less one that works.
Continue readingangular mock `module` resulting in '[Object object] is not a function'
Issue I’m trying to create some unit tests in Angular using Jasmine being run through Teaspoon. The tests are running, however I have a simple test just to test the existence of a controller that is failing. I have the
Continue readingJSHint and angular-mocks error
Issue When i run JSHint over my Jasmine tests using angular-mocks, i get errors for the “module” or “inject” function. How can I fix this? I know i can define those methods as globals in the .jshintrc, but is this
Continue readingWhy does expectPUT/POST/etc represent request bodies as a string?
Issue Look at the API for $httpbackend, we can see that functions like expectPut can take up to 4 parameters. The second parameter can be a function which takes 1 parameter: a string. This string represents the body of the
Continue readingHow to make a REST API call in a controller Unit test?
Issue I am trying to make a real call and Assign Scopes for testing Using passThrough Method but Throwing Error Code Follows:- describe(‘Controller: MainCtrl’, function () { // load the controller’s module beforeEach(module(‘w00App’)); var scope, MainCtrl, $httpBackend; // Initialize the
Continue readingangular mocke2e, how to send real ajax, not caught by httpbackend
Issue angular mocke2e, how to send real ajax, not caught by httpbackend? I may want to send both mock and real ajax in my development. Solution You can passThrough any call came into httpBackend with its inbuilt method. $httpBackend.whenGET(‘AnyCall.html’).passThrough(); More
Continue readingngMock injecting $scope local into controller
Issue This is a continuation of another question I asked that was successfully answered. I’m learning how to unit test AngularJS applications with Karma, Jasmine, and ngMock. Here’s the code I have a question about: describe(‘myController function’, function() { describe(‘myController’,
Continue readingbrowserify/karma/angular.js "TypeError: Cannot read property '$injector' of null" when second test uses "angular.mock.inject", "currentSpec" is null
Issue I have an Angular.js app and am experimenting with using it with Browserify. The app works, but I want to run tests too, I have two jasmine tests that I run with karma. I user browserify to give me
Continue readingAngularJS Unit Testing Controller w/ service dependency in Jasmine
Issue I’m brand new to testing, and I’ve been trying to find the best strategy for unit testing an AngularJS controller with a service dependency. Here’s the source code: app.service(“StringService”, function() { this.addExcitement = function (str) { return str +
Continue readingWhy am I losing my invocation context when testing code inside of a promise (angular + jasmine)
Issue I have simple controller where I want to test mechanics inside of a promise (in this case, I want to test that foo was called when I run bar. Here’s my controller: angular.module(‘myModule’, []) .controller(‘MyCtrl’, function ($q) { var
Continue readingJasmine and angular mocks : mocking a service that handles local storage
Issue I have one service called wd$cache, that is basically a wrapper for localStorage.setItem and get.item. Now I’m trying to test a controller that uses that service to achieve a certain result. The main problem is that I have an
Continue readingAngularJS Testing and $http
Issue So Im trying to figure out how to write unit tests for my angular controller. I am using karma as my runner. I was able to write 1 successful test but every time I try to write another test
Continue readingJasmine spyOn on function and returned object
Issue I’m using MeteorJS with angular and want to test controller. My controller use $reactive(this).attach($scope). I need to check, if this method was called. I create something like that for spy: var $reactive = function(ctrl) { return { attach:function(scope) {}
Continue readingWhy am I getting this Angular-Mock error and Mocha test is not running
Issue I’m getting the exact error as found here: (window.beforeEach || window.setup) is not a function. However the fix did not work, the author of the tutorial series here even mentioned the same fix. Here is the Tuts+ author’s fix:
Continue readingCordova sqliteplugin karma test description
Issue Hello I want to implement some test cases for my ionic framework application which uses cordova sqliteplugin to get data from a sqlite database. I’m very new in writing test cases for angularjs. My goal is to test if
Continue readingHow to unit test (using Jasmine) a function in a controller which calls a factory service which returns a promise
Issue In the below SampleController, how do I unit test that postAttributes function calls sampleService.updateMethod. I’m having trouble since the updateMethod returns promise. angular.module(‘sampleModule’) .controller(‘SampleController’, SampleController); SampleController.$inject =[‘sampleService’]; function SampleController(sampleService){ this.postAttributes = function() { sampleService.updateMethod(number,attributes) .then(function(response){ //do something on successful
Continue readingAngular services not being defined in beforeEach in Karma
Issue I have an Angular Application using Jasmine and Karma for testing. This is my testing class: var data = require(‘./user.mock.js’); describe(‘Service: UserService’, function () { var ServerUrl; var httpBackend; var userService; beforeEach(angular.mock.module(‘myModule’)); beforeEach(angular.mock.inject(function (_userService_, $httpBackend, _ServerUrl_) { userService =
Continue readinghttpBackend.expectPUT not working in angularjs factory unit test
Issue Below is the sample service that I’m trying to unit test: angular.module(‘sampleModule’) .factory(‘sampleService’, sampleService); sampleService.$inject = [‘$http’]; function sampleService($http) { var endpoint = “http://localhost:8088/api/customers/” return { getData: function(id){ return $http({ method: ‘GET’, url: endpoint + id }); }, updateData:
Continue readingWhat is the difference between calling _$controller_ instead of _$injector_.get('$controller')?
Issue beforeEach(inject(function (_$controller_, _$injector_) { ctrl = _$controller_(…) // 1 ctrl = _$injector_.get(‘$controller’)(…) // 2 })); What are the differences and which way is preferred? Solution Declaring _$controller_ in the parameters of the function passed to inject() makes the framework
Continue readingUnit Testing $routeParams in directive
Issue I have a directive that accesses the $routeParams of the page as such: myApp.directive(“myList”, function ($routeParams) { return { restrict: ‘E’, templateUrl: ‘tabs/my-list.html’, link: function (scope) { scope.year = $routeParams.year; } }; }); The directive works as expected and
Continue readingController not invoking then with mock service's deferred
Issue I am trying to mock a method in a service that returns a promise. The controller: app.controller(‘MainCtrl’, function($scope, foo) { var self = this; this.bar = “”; this.foobar = function() { console.log(‘Calling the service.’); foo.fn().then(function(data) { console.log(‘Received data.’); self.bar
Continue readingAccessing $http data in Protractor / E2E tests (AngularJS)
Issue I have a bunch of Unit tests that are going well, and I’ve started to add Protractor E2E tests to my project. I’m doing okay testing interactive elements on the page, but I’m having trouble testing for certain data
Continue readingMocking $window object inside Angular .config
Issue I am getting following error while trying to run karma tests spec in my app. Error: [$injector:modulerr] Failed to instantiate module adf.widget.tabularWidget due to: Error: Failed to execute ‘atob’ on ‘Window’: The string to be decoded is not correctly
Continue readingTesting $interval in Jasmine/ Karma
Issue I have a simple factory angular.module(‘myApp.dice’,[]).factory(‘Dice’, [‘$interval’, function($interval){ return { rollDice: function(){ return $interval(function(c){ count++; }, 100, 18, false, 0); } }; }]); In my test case I have describe(‘rolling dice’, function(){ var promise, promiseCalled = false, notify =
Continue readingPermission denied to clone angular-mock from git
Issue I’m using angular-mock in bower and when I do bower install, I’m getting following error: ECMDERR Failed to execute “git ls-remote –tags –heads https://github.com/angular/bower-angular-mocks.git“, exit code of #128 Permission denied (publickey). fatal: Could not read from remote repository. Please
Continue readinghow is angular mock's httpBackend passed implicitly to the $controller service in tests?
Issue This spec passes, even though it looks like it should fail. (the code is from a book on angular and rails) here is the angular app: var app = angular.module(‘customers’,[]); app.controller(“CustomerSearchController”, [“$scope”, “$http”, function($scope, $http) { var page =
Continue readingDoes Angular $httpBackend whenPUT() behave differently than whenGET()?
Issue I am writing the beginning of an Angular service that will consume an API, and I started with stubbing out all the request actions. Nothing actually happens with this service yet; it’s basically a wrapper for $http. I’m running
Continue readingangular unit test $httpBackend got Unexpected request
Issue Here is my code: export class httpService { constructor($q, $http){ this.$q = $q; this.$http = $http; } static getError(response) { if (response.data && response.data.messages) { return response.data.messages; } else { return [“Sorry, there is an internal issue…”]; } }
Continue readingUnable to inject controller to Karma test
Issue I have spent hours trying to set up unit testing on an existing angularjs code base. I believe I have pinned the issue down to a single oddity in our code compared to the suggested implementation from angular’s docs.
Continue readingKarma – Unknown provider error: menuFactoryProvider <- menuFactory
Issue When trying to test my controller, Karma fails with a string of errors all beginning with: Karma – Error: [$injector:unpr] Unknown provider: menuFactoryProvider <- menuFactory It seems menuFactory (which is actually a service now) isn’t properly injected, but I
Continue readingController is undefined in jasmine test
Issue karma.config.js: module.exports = function(config) { config.set({ basePath: ”, frameworks: [‘jasmine’], files: [ ‘node_modules/angular/angular.min.js’, ‘node_modules/angular-mocks/angular-mocks.js’, ‘node_modules/angular-translate/dist/angular-translate.min.js’, ‘browser/javascripts/*.js’, ‘browser/tests/*.spec.js’ ], exclude: [], preprocessors: {}, reporters: [‘progress’], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: [‘Chrome’], singleRun: false, concurrency: Infinity })
Continue readingHow to test $scope in Jasmine test?
Issue I trying to write unit tests for Angularjs with Jasmine. Here is my controller: function HomeController($scope, fav, news, materials) { console.log(‘home controller’); $scope.testMe = true; } module.controller(‘HomeController’, HomeController); And tests describe(‘Home controller tests’, function() { var $rootScope, $scope, controller;
Continue readingWhat is the difference between expect and when in $httpBackend
Issue What is the difference between $httpBackend.when(”) and $httpBackend.expect(”)? I don’t know the difference between these two methods. Also the angularjs api doc does not help me. API documentation link: https://docs.angularjs.org/api/ngMock/service/$httpBackend Solution $httpBackend.expect – specifies a request expectation $httpBackend.when –
Continue readingWhy does this test for the angular-google-maps provider fail?
Issue I’m trying to test a module that uses angular-google-maps. It is failing because angular.mock.inject cannot find uiGmapGoogleMapApiProvider: Error: [$injector:unpr] Unknown provider: uiGmapGoogleMapApiProviderProvider <- uiGmapGoogleMapApiProvider I can’t figure out what is going wrong. Here is the reduced testcase: ‘use strict’;
Continue readingHow to test the config function of an Angular module?
Issue I’m defining some setup code in the config function of an Angular module that I want to unit test. It is unclear to me how I should do this. Below is a simplified testcase that shows how I’m getting
Continue readingTesting a custom method for $state.go
Issue I tried to test this code: redireccion() { this.$state.go(‘modifyLine’, {lineId: this.look()._id}); } look() { return Entries.findOne({name: this.entry.name}); } the code above method is ok (look), but for ‘redireccion’ I tried something like this and i got an error. this
Continue readingUnit test controller
Issue I make an ionic app and it finish but when i start to add tests to it I face a problem with $resources ,in this case I have this Controller : .controller(‘newAccountCtrl’, function($scope, $window, $rootScope, API, $ionicPopup, $state) {
Continue readingkarma test returning validateAmount is not a function
Issue I’m trying to test scope function which will check due amount, but while running the test I’m getting validateAmount is not a function. app.js var ManagmentApp = angular.module(“ManagemntApp”, [‘ngRoute’, ‘angularModalService’, ‘ng-fusioncharts’]); ManagmentApp.config([‘$routeProvider’, function ($routeProvider){ $routeProvider.when(‘/’, { templateUrl: ‘templates/CandidateForm.html’, controller:
Continue readingTest a directive function through watch
Issue I have a function in angular directive that gets triggered on watch. How do i test the timeout based scrolling activity of the function scroll since its not in scope? scope.$watch(‘elementId’, function(value) { //How do i test scroll function
Continue readingHow to use ngMock to inject $controller
Issue I’m trying to learn unit testing for Angular using Karma, Jasmine, and ngMock. There are at least 2 places in the Angular docs that show how to write unit tests for a controller, and I just have a couple
Continue readingHow to unit test module with provider dependencies?
Issue I have an existing angular app. Now I want to start with some unit tests. I use jasmine and karma to test my services. My problem is that I am not able to test a service with the $stateProvider
Continue readingJasmine test error on Jenkins Build Server with angular-mocks?
Issue I’m unit testing a angular directive with Angular and Jasmine. Mocking the http backend works fine and all tests working fine locally. But on the build server i get: Error: Unexpected request: GET app/auth/views/login.html No more request expected (line
Continue readingTypeError: angular.element.cleanData is not a function
Issue I’m getting the following error in my karma unit test when trying to use inject() Example ✗ should wait for promise to resolve and have a result Error: timeout of 2000ms exceeded. Ensure the done() callback is being called
Continue readingAngular Mock Inject throws error without message using Karma and Jasmine
Issue Using the angular.mock.inject(…) function when trying to unit test an Angular (Ionic) 1 application throws the following error. The strange thing is that there is no specific error message, making particularly hard to debug. No matter what I try,
Continue readingUnit test $mdDialog angular material
Issue I called one $mdDialog inside a function. I want to unit-test $mdDialog ok and cancel cases. The below is my controller code (app.controller.js). (function () { ‘use strict’; app.controller(‘AppCtrl’, AppCtrl); AppCtrl.$inject = [‘$scope’, ‘$mdDialog’]; function AppCtrl($scope, $mdDialog) { $scope.saveEntry
Continue readingHow can I unit test the result of a ui-bootsrap $uibModal instance?
Issue I have a controller that calls $uibModal.open to pop a ui-bootstrap modal. The controller looks like this: (function () { ‘use strict’; angular .module(‘app’) .controller(‘MyCtrl’, myCtrl); function myCtrl($uibModal) { var vm = this; vm.showModal = showModal; vm.results = [];
Continue readingGetting a `$digest already in progress` error when testing a `catch()` error handler
Issue This is my test: it(‘add.user() should POST to /users/, failure’, function() { mockBackend.expectPOST(“/users/”, {username:’u’, password: ‘p’, email: ‘e’, location: ‘loc’}).respond(400, {msg: “bad request”}); BaseService.add.user({username:’u’, password: ‘p’, email: ‘e’, location: ‘loc’}); mockBackend.flush(); }); afterEach(function() { mockBackend.verifyNoOutstandingExpectation(); mockBackend.verifyNoOutstandingRequest(); }); And when
Continue readingCheck $scope variable with jasmine return error
Issue Currently trying to check very simple angular variables and functions. I cannot get even the simplest to work. This is my first time using it, and I need to use the older version as my lecturer requires it. In
Continue readingCircular dependencies on angular modules using typescript
Issue I’m facing this issue where i have 2 angular 1.5 modules that depend on each other, which is fine by angularjs, but when i import them using typescript & webpack, i get circular typescript-module dependencies and the modules are
Continue readingtypescript importing wrong angular
Issue I am importing angular in my angular 1 app (in typescript) using syntax like below import * as angular from ‘angular’; This imports angular from angular-mocks and not from angular because of which my ILogService implementation fails ERROR in
Continue readingMock back-end responses in Angular 2
Issue In my application made with Angular 1, I’ve used angular-mocks to build front-end without requiring the back-end to be up and running: (function() { angular .module(‘myapp’) .run([‘$httpBackend’, function($httpBackend) { $httpBackend.whenGET(/.*\/api\/ratings\/\?.*/).respond(function(method, url) { var params = matchParams(url.split(‘?’)[1]); var list =
Continue readingHow to test angularjs component with DOM
Issue I am trying to get familiar with testing an AngularJS application. While testing component logic is clear more or less, I have a trouble with html templates and model binding, because I’d like to test html binding together with
Continue readinginjecting test mock data into protractor mock module
Issue In my protractor e2e tests, I want to use mock data for httpBackendMock. However I am not able to access/inject the data into mock module. Below is my coffee code. describe ‘my test page’, -> ptor = protractor.getInstance() page
Continue readingSetting up webpack karma and angular-mocks
Issue I have this problem setting up my webpack. I’m setting up webpack on an existing project and additionally I’m introducing ES6. I would like to do it in the ‘correct’ manner having tests passing after some big change.That’s why
Continue readingAngular 1.5 Karma unit test loads ng-mock twice
Issue I have a web app written with Typescript 2.4.2, compiled by latest Webpack version (2.7.0). I’m in the process of adding Karma tests using Jasmine as the assertion library. This is my karma config file: ‘use strict’; const webpack
Continue readingUnit testing AngularJS Directives with Jest
Issue I feel I am missing something crucial in this extremely simplified angular directive unit test: import * as angular from ‘angular’ import ‘angular-mocks’ const app = angular.module(‘my-app’, []) app.directive(‘myDirective’, () => ({ template: ‘this does not work either’, link:
Continue readingHow to mock an angular $http call and return a promise object that behaves like $http
Issue Is there a way to return an HttpPromise (or something similar) to mimic a call to $http? I want to set a global variable that indicates whether the real HTTP request is made or whether a fake HttpPromise object
Continue readingAngularJs $httpbackend.whenPOST regular expression not working
Issue am getting an error Error: Unexpected request: POST data/employee/1 No more request expected Am using angular-mocks, angular-ui-route in my app.config i’ve got my $stateProvider routes and my mocks the main one with the issue being the one below: $httpBackend.whenPOST(/data\/employee\/(\d+)/,
Continue reading