Question

In the script I'm developing, I check to see if a variable is instanceof HTMLAudioElement. When I run QUnit via a grunt task, it fails with

>> Message: Died on test #1     at file:///path/test/lib/qunit.js:425
>>     at file:///path/test/all.js:24: Can't find variable: HTMLAudioElement
>> ReferenceError: Can't find variable: HTMLAudioElement

all.js doesn't actually reference HTMLAudioElement itself, it just calls some code in my main script that would use it.

All the tests pass when I open all.html in Firefox, Chrome, or Safari.

Is this expected behavior? Is it using some sort of browser emulation that doesn't have that constructor? Does this mean that my code will fail in some browser, or is this just misconfiguration that doesn't tell me anything useful? How do I fix it?

Was it helpful?

Solution

Sorry friend, but according to their website, PhantomJS does not support the HTML5 audio or video elements, thus the HTMLAudioElement constructor will not exist.

You can get your tests to pass by having a condition around that code checking for compatibility with unsupported browsers, maybe using something like Modernizr?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top