Javascript 如何编写jasmine测试用例来检查click事件中的Toggle类功能
我有一个指令,它基本上执行类在元素上的切换。工作正常。但是jasmine的测试用例出了问题 })) Jasmine测试用例:Javascript 如何编写jasmine测试用例来检查click事件中的Toggle类功能,javascript,angularjs,karma-jasmine,Javascript,Angularjs,Karma Jasmine,我有一个指令,它基本上执行类在元素上的切换。工作正常。但是jasmine的测试用例出了问题 })) Jasmine测试用例: describe( 'testing toggle-class directive', function() { var $compile, $rootScope; beforeEach(module('myApp')); beforeEach(inject(function(_$compile_, _$
describe(
'testing toggle-class directive',
function() {
var $compile, $rootScope;
beforeEach(module('myApp'));
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
it('should set highlight class on report title',
function() {
var element = $compile("<div toggleclass='highlighted'</div>")($rootScope);
element.click();
expect(element).toHaveClass('highlighted');
});
});
描述(
“测试切换类指令”,
函数(){
var$compile,$rootScope;
在每个模块之前(模块(‘myApp’);
beforeach(注入函数($compile,$rootScope){
$compile=\$compile;
$rootScope=\u$rootScope;
}));
它('应在报告标题上设置突出显示类',
函数(){
var element=$compile(“toHaveClass
不是Jasmine
的一部分。
尝试以下方法:
expect(element.attr('class')).toEqual('highlighted');
我已经抢注了。谢谢!!!.bdw通过属性检查类不起作用。我似乎使用了hasClass!。expect(element.hasClass('highlighted')).toBe(true);@BharatSewani检查类属性起作用。测试成功运行。请重新检查plunkr。您使用的是什么Jasmine版本?
expect(element.attr('class')).toEqual('highlighted');