title: Angular controller test on scope.variable is undefined
body: <p>I'm trying to learn angular unit test with $resource.</p>
  
  <p>Here I have a simple controller :</p>
  
  <pre><code>.controller('DictionaryCtrl', function ($scope, DictionaryService) {
  
    $scope.jSearchDictionary = function () {
      $scope.word = DictionaryService.getByJword({ jp: $scope.jword });
    }
  
    $scope.eSearchDictionary = function () {
      $scope.word = DictionaryService.getByEword({ eng: $scope.eword });
    }
  })
  </code></pre>
  
  <p>In my view, I have 2 ng-submit (jSearchDictionary and eSearchDictionary) and i bind the corresponding word that is searched ( jword or eword ).</p>
  
  <p>The service is also quite simple :</p>
  
  <pre><code>.factory('DictionaryService', function ($resource) {
    return $resource('http://127.0.0.1:3000/api/nlp/words', {}, {
      getByJword: { method: 'GET', params: { jp: '@jword' } },
      getByEword: { method: 'GET', params: { en: '@eword' } },
    })
  })
  </code></pre>
  
  <p>Finally, here is my test.</p>
  
  <pre><code>describe('Controller: nlpCtrl', function () {
  
  beforeEach(function () {
    this.addMatchers({
      toEqualData: function (expected) {
        return angular.equals(this.actual, expected);
      }
    });
  });
  
  beforeEach(module('gakusei'));
  
  describe('nlpCtrl', function () {
  var scope,
      $controller,
      $httpBackend,
      $stateParams,
      Eword,
      mockWord = [
      {
        "words": [
            {
              "readings": [
                  "ホッケー"
              ]
            }
        ],
        "count": 1
      }];
  
  beforeEach(inject(function (_$httpBackend_, $rootScope, _$controller_) {
    scope = $rootScope.$new();
    $controller = _$controller_;
    $httpBackend = _$httpBackend_;
  }));
  
  afterEach(function () {
    $httpBackend.verifyNoOutstandingExpectation();
    $httpBackend.verifyNoOutstandingRequest();
  });
  
  it('should get a word', inject(function (DictionaryService) {
    Eword = "englishWord";
    $httpBackend.expectGET('http://127.0.0.1:3000/api/nlp/words?eng=englishWord')
      .respond(mockWord[0]);
  
    var ctrl = $controller('DictionaryCtrl', { $scope: scope });
    var request = DictionaryService.getByEword({ eng: Eword })
  
    $httpBackend.flush();
  
    expect(scope.word).toEqualData(mockWord[0]);
    expect(BasketService.getByJword).toBeTruthy();
    expect(BasketService.getByEword).toBeTruthy();
  }));
  });
  });
  </code></pre>
  
  <p>The problem is at the line :</p>
  
  <pre><code>expect(scope.word).toEqualData(mockWord[0]);
  </code></pre>
  
  <p>scope.word being undefined. Unit Testing is way over my head right now, I'm not sure of what I'm doing at all. If you have a solution to this particular problem, have any advices at all concerning all the code or are willing to message me and guide me a little, that would be awesome.</p>