为什么此 angularjs 测试在 1.5.x 中有效,但在 1.6.x 中无效?
Why does this angularjs test work in 1.5.x but not in 1.6.x?
以下被阻止的代码在过去两年中在 AngularJS 1.4 和 1.5 中没有问题。但是,我们最近更改为 angularjs 1.6,但测试失败。在我尝试的所有 angularjs 版本中,编译的元素似乎都是正确的。 (<h2 class="ng-binding">Bill</h2><p class="ng-binding">Age: 29</p>
) 似乎失败的是find()
的结果。在 1.5 中,elem.find('h2').html()
returns 预期的字符串。在 1.6 中,elem.find('h2').html()
returns 未定义。我查看了变更日志,但没有任何帮助我解决问题。我错过了什么?
describe('wppicd-child Directive', function() {
var elem, scope;
beforeEach(function() {
angular.mock.module(ngModuleName);
angular.mock.inject(function($rootScope, $compile) {
var elemT = ('<wppicd-child ' +
'child="child">' +
'</wppicd-child>');
scope = $rootScope.$new();
scope.child = {
name: 'Bill',
birthday: new Date('April 8, 1988')
};
elem = $compile(elemT)(scope);
scope.$digest();
});
});
it('should have correct title', function() {
expect(elem.find('h2').html()).toContain('Bill');
});
});
虽然我不知道确切的问题,但解决方案是将 PhantomJS 从 1.x 升级到 2.x。我们之前没有这样做,因为 CI 服务器上的库冲突已经解决。升级到 2.x 后,构建再次运行。
以下被阻止的代码在过去两年中在 AngularJS 1.4 和 1.5 中没有问题。但是,我们最近更改为 angularjs 1.6,但测试失败。在我尝试的所有 angularjs 版本中,编译的元素似乎都是正确的。 (<h2 class="ng-binding">Bill</h2><p class="ng-binding">Age: 29</p>
) 似乎失败的是find()
的结果。在 1.5 中,elem.find('h2').html()
returns 预期的字符串。在 1.6 中,elem.find('h2').html()
returns 未定义。我查看了变更日志,但没有任何帮助我解决问题。我错过了什么?
describe('wppicd-child Directive', function() {
var elem, scope;
beforeEach(function() {
angular.mock.module(ngModuleName);
angular.mock.inject(function($rootScope, $compile) {
var elemT = ('<wppicd-child ' +
'child="child">' +
'</wppicd-child>');
scope = $rootScope.$new();
scope.child = {
name: 'Bill',
birthday: new Date('April 8, 1988')
};
elem = $compile(elemT)(scope);
scope.$digest();
});
});
it('should have correct title', function() {
expect(elem.find('h2').html()).toContain('Bill');
});
});
虽然我不知道确切的问题,但解决方案是将 PhantomJS 从 1.x 升级到 2.x。我们之前没有这样做,因为 CI 服务器上的库冲突已经解决。升级到 2.x 后,构建再次运行。