David Heidelberg
David Heidelberg

Reputation: 25

how to test to see if an element exists in DOM in Jasmine Jquery

I need to write a unit a test to see if a DOM element exists using Jquery jasmine. I have used standalone jasmine and included Jquery Jasmine and Jquery CDNs into my SpecRunner.html

Upvotes: 2

Views: 2076

Answers (1)

Ramin Ahmadi
Ramin Ahmadi

Reputation: 629

if you look into jasmine-jquery GitHub page you'll find toBeInDOM() matcher which checks that. here is an example of code that you need to include in your spec folder. just remeber that it is important to get the path to HTML right. look for console logs for any possible issue with path to your fixture.

    describe("Dom element Test", function () {
        beforeEach(function () {
            loadFixtures('path/to/your/fixture.html');
        });

        it("should be in HTML page", function () {
            expect($('#ID-of-your-html-elemnt')[0]).toBeInDOM()
        });

    });

Upvotes: 1

Related Questions