Jasmine jQuery: check if element is displayed

Hello, I had a question about unit testing with Jasmine (plugin: jQuery)

How can I check if an object is inside a DOM of a document. The fact is that I use the tooltip function, which will be activated only when the event is simulated. When there is a simulation of the effect, the object is attached to the DOM, and I want to check whether 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');                                                            
});
+4
source share
1 answer

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

Yes Yes. In testing a jasmine unit, so it passes the test, you expect this to be true:

expect($('.tooltip').is(':visible')).toBe(true); // Passes
expect($('.tooltip').is(':visible')).toBe(false); // Fails
+6
source

Source: https://habr.com/ru/post/1599333/


All Articles