I am new to writing unit test. I am trying simple thing, In my saveInfo function in controller $scope.practice should contain a value.
I am using webstorm to run my test. I want to check in saveInfo function that $scope.practice is defined or not.
test / practice.js
'use strict';
describe('myApp', function() {
describe('Controller: PracticeCtrl', function () {
var $http, $scope, $routeParams, $location, $locale, $timeout;
// load the controller's module
beforeEach(function () {
// Load the controller's module
module('myApp');
inject(function ($controller, $rootScope) {
$scope = {};
});
});
it('should define a practice property', function () {
expect($scope.practice).toBeDefined();
});
});
});
practice.js - controller
angular.module('myApp').controller('PracticeCtrl', function ($http, $scope, $routeParams, $location, $locale, $timeout) {
$scope.saveInfo = function () {
$scope.practice = '52300099';
Practices.updateStampApproval().updateInfo($scope.practice);
};
$scope.updateInfo = function () {
....
}
$scope.getInfo = function () {
....
}
Gives me Error :-
Expected undefined to be defined.
Error: Expected undefined to be defined.
In my controller $scope.practice is defined. so why it shows error.
And how to test function wise means how do i write test which will check only in 1 function in controller e.g. 'saveInfo'?