Closed cedricdelpoux closed 7 years ago
Since Jest uses JSDOM instead of a real browser environment, it won't have an actual <script>
in the document like you'd find in a real scenario (there will only be an empty placeholder document created by JSDOM).
I can think of a couple options:
<script>
tag to the document in the setup/before method of your test. That way the document will reflect what a real browser's would look like. This could look like:
before(() => {
const script = document.createElement('script');
document.body.appendChild(script);
})
little-loader
since you're sort of testing too much by actually calling it – if it's a unit test you really only want to test your own code. It's also often considered bad practice for your test suite to actually hit the network (for this reason, I might recommend mocking out little-loader
even if your tests were running in a real browser environment and working). In Jest you can use mock.fn() to do this.Thank you very much, the first solution works for me
When I try to test my loading function using Jest, I get this error.
I found this error in an old issue too #37 .
What is your recommandation to test your lib using a test runner like Jest ? Thank you