My <custom-directive>
はreplace:true
とtemplate: '<img />'
です。 ユニットテストを書くにはどうしたらいいですか?実際にはimgでカスタムディレクティブを置き換えることをテストしたいと思う。Replaceをtrueに設定した指令をAngularJSがテストします
it('should be transformed to <img>', function(){
var elm = $compile('<custom-directive></custom-directive>')(scope);
scope.$digest();
var t = elm.find('img'); // wrong! it replaces the element. it won't find another one inside
//expect(elm).toBeAnImgElement ?
});
正しいマッチャーが見つかりません。 私が見た中で最も近いのは内容(elm.html()
またはelm.text()
)のチェックですが、私のタグは空です。
$ダイジェスト();'ここに。?確かに、それはそれなしで動作しませんが、私はなぜ取得しません。 – thorn
@thorn:それは必須ではありません。 – codef0rmer
いいえ、そうです。私が書いたように、それなしでは動作しません。 – thorn