Headless JavaScript HTML5 Audio / Video Testing

I know that there are many other similar questions, but the answers do not provide an opportunity to get around this problem.

I have a JavaScript file that is used on my website that uses HTML 5 Web Audio and wants to unit test it.

I looked at using QUnit with PhantomJS and before you say anything I know Phantom does not support it ( http://phantomjs.org/supported-web-standards.html ), however I want to know if way to get around this?

Testing with QUnit in the browser works as you expected, but I do not want to test it with the browser every time, I want it to be automated on the server.

An example of one of the failed tests:

QUnit.test("isPlaying", function(assert){ // true case My.Sound.play("background"); assert.ok(My.Sound.isPlaying("background"), "The background audio is playing"); // false case My.Sound.pause("background"); assert.ok(!My.Sound.isPlaying("background"), "The background audio is not playing"); }); 
+7
javascript unit-testing qunit phantomjs headless
source share
1 answer

As @jakerella already noted, it makes no sense to test third-party Apis. Just focus on your functionality. In this case, you should check that whenever you want to play / pause the sound, you call the correct api methods for your sound object (play / pause), which should be stubs of the original implementations.

 QUnit.test("play button should play sound when clicked", (assert) => { const button = someButton; //...get your button / play trigger here const playStub = stub(My.Sound, 'play'); //trigger button click assert.ok(playStub.called); }); 

Look here for copy functions using QUnit.

0
source share

All Articles