Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine jQuery: Check if element is visible

Hello I got a question regarding unit testing with Jasmine (plugin: jQuery)

How could I test if the object is within the DOM of a document. The thing is that I use a tooltip function which will only be activated when an event is simulated. When there is a simulation of the effect, an object is attached to the DOM and I want to check if it is visible or not.

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');                                                            
});
like image 800
Rotan075 Avatar asked Jul 23 '15 14:07

Rotan075


1 Answers

You commented IN JQUERY would that be: $('.tooltip').is(':visible');

Yes it would. In jasmine unit testing, so it passes the test, you're expecting the above to be true:

expect($('.tooltip').is(':visible')).toBe(true); // Passes
expect($('.tooltip').is(':visible')).toBe(false); // Fails
like image 123
actaram Avatar answered Nov 04 '22 17:11

actaram