私のスコープ変数でHTMLのレンダリングをテストしたいと思います。
HTMLは以下の通りである2 <textarea>
を有する:
<textarea ng-model="a" ng-change="someFunction(a)" value={{a}}></textarea>
<textarea ng-model="b" ng-change="someFunction(b)" value={{b}}></textarea>
a
とb
は、a = someFunction(b)
とb=someFunction(a)
そのスコープ変数です。
説明:a
を入力すると、someFunction(a)
という関数が呼び出され、テキストエリアのテキストがb
に変更されます。その逆も012です。次のように
Iが書いたユニットテストは次のとおり
var compile,
scope,
tc,
template,
controller,
httpGuy;
beforeEach(inject(function($compile, $rootScope, $templateCache, $controller, $httpBackend) {
scope = $rootScope.$new();
controller = $controller('ABCController', {'$scope': scope});
compile = $compile;
template = $templateCache.get('app/index.html');
}));
it('test1', function() {
scope.a = SOME_VALUE;
scope.someFunction(scope.a);
// at this point scope.b changes to correct value
var html_template = compile(template)(scope); // this should insert the scope variables in html?
scope.$digest();
console.log(angular.element(html_template.find('textarea')[1]));
});
試験はvalue=""
すなわち空で<textarea>
の出力を与えます。スコープ変数をHTMLに導入したので、値がレンダリングされているはずです。 なぜこれは起こりませんか?
の下に使用し、その後、スコープにいくつかの値を設定し、特定のスコープのオブジェクトと
template
をコンパイルしたいしたい場合そのa = someFunction(b)とb = someFunction(b)」となります。 – georgeawgに説明が追加されました。 – saruftw
'ABCcontroller'のコードを表示します。 – georgeawg