cloudcmd/client/dom/dom-tree.spec.js

46 lines
1.1 KiB
JavaScript

'use strict';
const test = require('supertape');
const {create} = require('auto-globals');
const tryCatch = require('try-catch');
const {isContainClass} = require('./dom-tree');
test('dom: isContainClass: no element', (t) => {
const [e] = tryCatch(isContainClass);
t.equal(e.message, 'element could not be empty!', 'should throw when no element');
t.end();
});
test('dom: isContainClass: no className', (t) => {
const [e] = tryCatch(isContainClass, {});
t.equal(e.message, 'className could not be empty!', 'should throw when no element');
t.end();
});
test('dom: isContainClass: contains', (t) => {
const el = create();
const {contains} = el.classList;
const className = 'hello';
isContainClass(el, className);
t.ok(contains.calledWith(className), 'should call contains');
t.end();
});
test('dom: isContainClass: contains: array', (t) => {
const el = create();
const {contains} = el.classList;
const className = 'hello';
isContainClass(el, [
'world',
className,
'hello',
]);
t.ok(contains.calledWith(className), 'should call contains');
t.end();
});