i have been trying to set up this test for a long time now...i really dont get what's not working here.
my Angular app:
<body ng-app="testApp">
<div class="container" droppable>
<div class="row"><navi></navi></div>
<div class="row">
<div class="col-xs-8">
<preview></preview>
<editor></editor>
</div>
<div class="col-xs-4">
<iframe src="" pull-down></iframe>
</div>
</div>
</div>
the controller:
testApp.controller('previewController', ['$scope', '$http', function($scope, $http) {
$scope.tmp = "test";
console.log("init controller");
$.ajax({
url: "http://localhost/angularjs_testapp/request.php",
type: "POST",
success: function(data){
console.log("server data:");
console.log(data);
$scope.data = data;},
error: function(data){
console.log("error occured");
console.log(data);
}
});
}]);
and at least the test:
describe('previewController', function() {
beforeEach(module('testApp'));
var scope, createController;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
createController = $controller('previewController', {
'$scope': scope
});
}));
it('should be "test":', function(done) {
console.log(scope);
expect(scope.tmp).toBe("test"); //working
expect(scope.data).toBe("hallo"); //not working
});
});
the server returns the ajax return value correctly if I just call it at the website. But out of the testing environment its not working. It seems like he is not communicating with the server. I made that a promise too, an also tried $http.post() instead of ajax to solve it, but its still not working. What am I doing wrong? May the karma engine fail the server communication?