Home » Javascript » javascript – How to inject script tag from template html in jasmine angularjs testing

javascript – How to inject script tag from template html in jasmine angularjs testing

Posted by: admin February 23, 2020 Leave a comment

Questions:

I am trying to inject a script tag which is in my template html for jasmine to use to run the test case.
Lets say the html file is :

<script>
 <!-- imagine there is some cool javascript code in here - actual code not a link-->
</script>
<div>
    <h2>Imagine a question here?</h2>
    <input type="checkbox">Yes</input>
    <input type="checkbox">No</input>
</div>

the .js file is able to see the js within the script tag because the html is being loaded when the application is being run, but jasmine will not since it is not injected yet. is this possible ? Can html be called in the jasmine tests?
I tried

$.getScript('link/to/html/page.html');

and

require('link/to/html/page.html');

but those didn’t work (or throw any errors)

How to&Answers: