Jasmine jQuery: Check if element is visible
Asked Answered
R

1

6

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');                                                            
});
Rosenberg answered 23/7, 2015 at 14:38 Comment(0)
C
9

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
Cholecalciferol answered 23/7, 2015 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.