Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have multiple functions and a lot of code inside $(document).ready(function())

ID: 646928 • Letter: I

Question

I have multiple functions and a lot of code inside $(document).ready(function()). I am using jasmine to test the functions inside the ready function as well as the code inside ready() but when the test cases inside describe are executed it is not able to access the code inside the ready function.

$(document).ready(function () {
    function testMe(){
        testVar = true;
    }
});
Jasmine test suite

describe("test suite", function(){
    beforeEach(function () {
        testme = false
    });
    it("Test Alert Box Message For Change Modal", function() {
        expect(testme).toEqual(true);
    });
});
Kindly suggest what approach needs to be taken for the above approach.

Explanation / Answer

in your code, domready calls an annonymous function. If we had a reference to this function, we could call it.

var> testVar = true;
}

$(document).ready(onReady);
and in your tests

it("Test Alert Box Message For Change Modal", function() {
var testVar = false;
onReady() ;
expect(testVar).toEqual(true);
});
your code is now testable :) namespacing and modules are recommended to make it even better.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote