How to set the <body> tag as a lamp in Jasmine
I am currently trying to test a JS function with Jasmine. Since the function checks the CSS classes set in the body tag, I want to use the <body> in the file:
setFixtures('<body class="themed someotherclass"></body>') The jQuery reference to this outlined HTML - $('body') - is then passed to the JS function that I am testing. But this body tag obviously never comes into the Jasmine test - it seems that Jasmine creates his own document with the body, and inside it he puts all the devices inside the div - at least when I repeat outerHTML from an element with a buried body I see this is inside the body and after the Jasmin-related embedded JS:
<div id="jasmine-fixtures"></div> which is empty when I try to drown out the body, but fills when I use a div .
Is there a way to silence a body tag in a Jasmine test?
Ok, I finally found a solution.
Whenever you want to stub a body tag using Jasmine, you first need to call "setFixtures ()" - during this call, Jasmine creates his own body tag. Therefore, after the body tag has been created, you can manipulate it, for example. using jQuery and then run the test, which depends on the changes you made to the body tag.
That is: I run my usual command "setFixtures (SOME HTML)" if necessary, or - if I only need the body tag for my test, I simply call "setFixtures ()" at the beginning of my test without any arguments. After that, at least in Jasmine version 1.x, the tag will be available, and I can use, for example, jQuery to configure / modify the body tag as I need it: $ ('Body') addClass ('thematic' ) So instead of mocking the body tag as a tool, I “create” the body tag by calling “setFixtures ()” without any arguments, and then manipulate the DOM as needed.