Jasmine jQuery:检查元素是否可见

Rot*_*075 6 javascript jquery jasmine jasmine-jquery

你好我有一个关于使用Jasmine进行单元测试的问题(插件:jQuery)

如何测试对象是否在文档的DOM中.问题是我使用的工具提示功能只有在模拟事件时才会被激活.当模拟效果时,对象附加到DOM,我想检查它是否可见.

it("test 1: should invoke the Tooltip() function.", function () {                               
        spyEvent = spyOnEvent('.span_width', "mouseover");                  
        $('.span_width').simulate('mouseover');                         

        expect('mouseover').toHaveBeenTriggeredOn('.span_width');
        expect(spyEvent).toHaveBeenTriggered();                             

        # A TEST TO check if .tooltip is visible???
        # IN JQUERY would that be: $('.tooltip').is(':visible');                                                            
});
Run Code Online (Sandbox Code Playgroud)

act*_*ram 8

你评论道 IN JQUERY would that be: $('.tooltip').is(':visible');

是的,它会的.在茉莉花单元测试中,所以它通过了测试,你期望以上是真的:

expect($('.tooltip').is(':visible')).toBe(true); // Passes
expect($('.tooltip').is(':visible')).toBe(false); // Fails
Run Code Online (Sandbox Code Playgroud)