我正在尝试测试我的指令,但在此之前,我想确保一切都设置正确。我正在尝试测试以下代码,但它不工作。我在我的项目中使用了require,到目前为止,我已经成功地测试了我的控制器。
define([
'angular',
'angular-mocks',
'Source/modules/common/directive/dynamic-forms/fields/index'
], function () {
describe('Dynamic fields directive in app.dynamic-form-fields', function () {
var scope, compile, element;
beforeEach(
module('app.dynamic-form-fields'));
beforeEach(function () {
inject(function ($rootScope, $compile) {
element = angular.element('<div class="well span6">' +
'<h3>Busdriver Albums:</h3>' +
'<albums ng-repeat="album in albums" title="{{album.title}}">' +
'</albums></div>');
scope = $rootScope;
scope.albums = [
{
'title': 'Memoirs of the Elephant Man'
},
{
'title': 'Temporary Forever'
}
];
$compile(element)(scope);
scope.$digest();
});
});
it("should have the correct amount of albums in the list", function () {
var list = element.find('li');
expect(list.length).toBe(2);
});
});
})输出=预期0为2。
发布于 2014-06-14 03:45:04
我很抱歉问这个愚蠢的问题。在期望值中设置的选择器不正确。
生成正确的html
<h3>Busdriver Albums:</h3>
<!-- ngRepeat: album in albums -->
<albums ng-repeat="album in albums" title="Memoirs of the Elephant Man" class="ng-scope"></albums><!-- end ngRepeat: album in albums -->
<albums ng-repeat="album in albums" title="Temporary Forever" class="ng-scope"></albums>
<!-- end ngRepeat: album in albums -->真的很抱歉。
https://stackoverflow.com/questions/24212130
复制相似问题