react-jw-player
Version:
A React component for launching JW Player instances on the client.
51 lines (40 loc) • 1.53 kB
JavaScript
import test from 'tape';
import installPlayerScript from '../src/helpers/install-player-script';
test('installPlayerScript()', (t) => {
let createElementCalled = false;
let createElementTag;
let appendChildElement;
let appendChildCalled = false;
const mockJWPlayerScript = {};
const mockContext = {
createElement(tag) {
createElementCalled = true;
createElementTag = tag;
return mockJWPlayerScript;
},
head: {
appendChild(element) {
appendChildCalled = true;
appendChildElement = element;
},
},
};
const mockOnLoadCallback = 'onLoadCallback';
const mockScriptSrc = 'scriptSrc';
const mockUniqueScriptId = 'uniqueScriptId';
const opts = {
context: mockContext,
onLoadCallback: mockOnLoadCallback,
scriptSrc: mockScriptSrc,
uniqueScriptId: mockUniqueScriptId,
};
t.doesNotThrow(installPlayerScript.bind(null, opts), 'it does not error');
t.ok(createElementCalled, 'it calls context.createElement()');
t.equal(createElementTag, 'script', 'it creates a script tag');
t.equal(mockJWPlayerScript.id, mockUniqueScriptId, 'it sets the script element id');
t.equal(mockJWPlayerScript.src, mockScriptSrc, 'it sets the script element src');
t.equal(mockJWPlayerScript.onload, mockOnLoadCallback, 'it sets the script element onload callback');
t.ok(appendChildCalled, 'it calls context.head.appendChild()');
t.equal(appendChildElement, mockJWPlayerScript, 'it appends the created script element');
t.end();
});