trying to test this script here.
can't access response.data values.


var app = angular.module('app', []);


app.controller('lookupRows', function($scope, $http) {

 var lookupRows = this;

 lookupRows.lookup = function() {
 $http({
 url: "api/numberOfRawsInTable/" + lookupRows.lookupTableName, //i.e: 
"api/numberOfRawsInTable/test" output is a json file in form of 'Object 
{name: "test", numberOfRows: 100}'
 params: {},
 config: {"cache": true }

 }).then(function(response) {
 lookupRows.response = response.data;
 $scope.testData = response.data; //this variable is not reachable from the 
test file (karma/jasmine)
 console.log(response.data); //this prints out on the browsers console.

 }, function myError(response) {
 alert('Could not download data.')
 });
 };

 lookupRows.lookupTableName = ""
 lookupRows.response = {
 name: "",
 numberOfRows: ""
 }
});





Whenever I try to get the values in response.data it says response is 
undefined.
if I test lookuprows.response.name or numberOfRows it expets ' ' and not 
test or 100.
i cant change to $scope, because then I have to change the html and a java 
rest endpoints.




My current tests:
describe('Test number of rows', function () {
 beforeEach(module('app'));
 var $controller;

 beforeEach(inject(function(_$controller_){
 $controller = _$controller_;
 }));

 describe('test if number of rowss is correct', function () {
 it('should be "100"', function () {
 var $scope = {};
 var controller = $controller('lookupRows', { $scope: $scope });


 controller.lookup("ff"); //just trying to see if this works

 console.log(controller.response);


 controller.lookup("ff");

 console.log(controller.response);


 controller.lookup("ff");

 console.log(controller.response);
 console.log($scope.testData);
 console.log(controller.response);
 console.log(
"--------------------------------------------------------------------")

 });
 });
});

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to