title: Testing ngResource with httpbackend - Possibly unhandled rejection error
body: <h3>Problem</h3>
  
  <p>I am attempting to test a the following controller using Karma, Mocha, Chai, PhantomJS  </p>
  
  <p><strong>IndexCtrl.js</strong> (simplified)</p>
  
  <pre><code>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");
        });       
    };
  }]);
  </code></pre>
  
  <p><strong>index.controller.test.js</strong> (again simplified, I have other non-http tests)</p>
  
  <pre><code>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('Changing the override should trigger the watcher', function () {
            $httpBackend.expectGET('/.*/', undefined).respond(200, {});
            $scope.testResource();
            $httpBackend.flush();
            expect($scope.someTestValue).to.equal(true);
        });   
    });
  });
  </code></pre>
  
  <p>When I run the test, I get the following error. If I comment out the flush line, it does not throw this error, but it does not work properly.</p>
  
  <pre><code>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@webroot/js/angular.compiled.min.js:4:16511\\nserverRequest@webroot/js/angular.compiled.min.js:4:12080\\nprocessQueue@webroot/js/angular.compiled.min.js:5:14235\\nwebroot/js/angular.compiled.min.js:5:15007\\n$eval@webroot/js/angular.compiled.min.js:5:46097\\n$digest@webroot/js/angular.compiled.min.js:5:43824\\nflush@node_modules/angular-mocks/angular-mocks.js:1813:45\\nweb-test/index.controller.test.js:18:22\\ncallFn@node_modules/mocha/mocha.js:4447:25\\nrun@node_modules/mocha/mocha.js:4439:13\\nrunTest@node_modules/mocha/mocha.js:4936:13\\nnode_modules/mocha/mocha.js:5042:19\\nnext@node_modules/mocha/mocha.js:4853:16\\nnode_modules/mocha/mocha.js:4863:11\\nnext@node_modules/mocha/mocha.js:4787:16\\nnode_modules/mocha/mocha.js:4831:9\\ntimeslice@node_modules/mocha/mocha.js:82:27\"}" was thrown, throw an Error :)
  </code></pre>
  
  <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": {
      "angular": "1.5.9",
      "angular-animate": "1.5.9",
      "angular-lazy-image": "^0.3.2",
      "angular-resource": "1.5.9",
      "angular-sanitize": "1.5.9",
      "angular-typewriter": "0.0.15",
      "angular-ui-router": "^0.3.2",
      "body-parser": "^1.15.2",
      "cookie-parser": "^1.4.3",
      "elasticsearch": "^12.1.3",
      "express": "^4.14.0",
      "grunt": "*",
      "grunt-contrib-sass": "*",
      "grunt-contrib-uglify": "*",
      "grunt-contrib-watch": "*",
      "grunt-html2js": "*",
      "grunt-notify": "*",
      "ldapjs": "^1.0.1",
      "request": "^2.79.0"
    },
    "devDependencies": {
      "angular-mocks": "^1.6.0",
      "chai": "^3.5.0",
      "karma": "^1.3.0",
      "karma-chai": "^0.1.0",
      "karma-chrome-launcher": "^2.0.0",
      "karma-cli": "^1.0.1",
      "karma-jasmine": "^1.1.0",
      "karma-mocha": "^1.3.0",
      "karma-phantomjs-launcher": "^1.0.2",
      "karma-requirejs": "^1.1.0",
      "mocha": "^3.2.0",
      "requirejs": "^2.3.2"
    }
  }
  </code></pre>
  
  <h3>Mods Note</h3>
  
  <p>This is different from <a href="https://stackoverflow.com/questions/41063947/angular-1-6-0-possibly-unhandled-rejection-error">Angular 1.6.0: &quot;Possibly unhandled rejection&quot; error</a> where the error was not triggered by a flush, and the solution was rolling back to angularjs 1.5.9. I have already tried rolling back to angular 1.5.9, to no avail. So for the love of god if I get another blind "marked as a duplicate"...</p>