Issue
Currently, I am working on testing a controller utilizing Karma, Mocha, Chai, and PhantomJS as part of the testing process.
IndexCtrl.js (simplified)
app.controller('IndexCtrl', ['$scope', '$resource', function($scope, $resource) {
var methods = {
get:{
method:'GET'
}
};
var Users = $resource('/api/v1/search/:search', {},methods);
$scope.testResource = function(){
Users.get({search: 'TEST'}, function(result){
$scope.someTestValue = true;
}, function(){
console.log("hello world");
});
};
}]);
index.controller.test.js (similarly simplified, with non-http tests)
describe('Index', function () {
var ctrl, $httpBackend;
beforeEach(module('myApp'));
beforeEach(inject(function($rootScope, $controller, $injector){
$httpBackend = $injector.get('$httpBackend');
$scope = $rootScope.$new();
ctrl = $controller('IndexCtrl', {
$scope: $scope
});
}));
describe('Search', function () {
it('Triggering the watcher by changing the override', function () {
$httpBackend.expectGET('/.*/', undefined).respond(200, {});
$scope.testResource();
$httpBackend.flush();
expect($scope.someTestValue).to.equal(true);
});
});
});
However, upon running the test, I encountered the following error. If I remove the flush line, the error does not occur, but the functionality does not operate as intended.
PhantomJS 2.1.1 (Mac OS X 0.0.0) Index Search Changing the override should trigger the watcher FAILED
the string "Possibly unhandled rejection: {\"line\":1421,\"sourceURL\":\"node_modules/angular-mocks/angular-mocks.js\",\"stack\":\"$httpBackend@node_modules/angular-mocks/angular-mocks.js:1421:90\\nsendReq@webroo...
<p><strong><em>package.json</em></strong></p>
<pre><code>{
"name": "myApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha",
"web-test": "node ./node_modules/karma/bin/karma start karma.conf.js"
},
"author": "",
"license": "ISC",
"dependencies": {
...
},
"devDependencies": {
...
}
}
Editor's Message
In comparison to the issue highlighted in Angular 1.6.0: "Possibly unhandled rejection" error, where the error wasn't triggered by a flush, and the remedy was reverting to AngularJS 1.5.9. Despite attempting to roll back to Angular 1.5.9 based on the suggestion, I have yet to resolve the problem. Consequently, if I receive another automatic "marked as a duplicate" response...