0
コントローラのメソッドのテストケースを記述する必要があります。そのコントローラーでは$scope
の代わりにthis
を使用しています。 $scope
を使用すると、以下のようにテストケースを書くことができます。しかし、コントローラでthis
を使用している場合、どのようにテストケースを書くことができますか?
app.controller('ExampleController', function(){
var test = this;
this.testFunction = function(){
return "Hello";
}
});
カルマ・テスト・ケースファイル
describe('app module', function() {
beforeEach(module('testAngularApp'));
describe('ContentController', function() {
var scope, controller;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller;
controller('ContentController', {
$scope: $scope
});
it('Should return Hello', function() {
expect(scope.testFunction()).toBe(true);
});
});