import test from 'tape'; import {$, $$, lastElement, elementExists, expectElement, ElementNotFoundError} from './index.js'; document.body.innerHTML = ` `; test('selects one element', t => { t.plan(1); const li = document.querySelector('ul li'); t.equal($('ul li'), li); }); test('selects one element within an ancestor', t => { t.plan(1); const li = document.querySelector('ul li'); t.equal($('li', $('ul')), li); }); test('expects at least one element', t => { t.plan(2); const li = document.querySelector('ul li'); t.equal(expectElement('ul li'), li); t.throws(() => expectElement('lololol')); }); test('expects one element within an ancestor', t => { t.plan(2); const li = document.querySelector('ul li'); t.equal(expectElement('li', expectElement('ul')), li); t.throws(() => expectElement('ul', expectElement('li')), error => error instanceof ElementNotFoundError); }); test('selects the last element', t => { t.plan(1); const li = [...document.querySelectorAll('ul li')].pop(); t.equal(lastElement('ul li'), li); }); test('selects the last element within an ancestor', t => { t.plan(1); const li = [...document.querySelectorAll('ul li')].pop(); t.equal(lastElement('li', lastElement('ul')), li); }); test('tests existence of one element', t => { t.plan(2); t.true(elementExists('ul li')); t.false(elementExists('lololol')); }); test('tests existence of one element within an ancestor', t => { t.plan(3); t.true(elementExists('li', $('ul'))); t.false(elementExists('ul', $('li'))); t.false(elementExists('ul', $('lololol'))); }); test('selects all elements', t => { t.plan(1); const li = document.querySelectorAll('ul li'); t.deepEqual($$('ul li'), [...li]); }); test('selects all elements within an ancestor', t => { t.plan(1); const li = document.querySelector('ul').querySelectorAll('ul li'); t.deepEqual($$('li', $('ul')), [...li]); }); test('selects all elements within an array of ancestors', t => { t.plan(1); const li = document.querySelectorAll('ul li'); t.deepEqual($$('li', $$('ul')), [...li]); }); test('selects all elements within an array of ancestors without duplicates', t => { t.plan(1); const li = document.querySelector('ul').querySelectorAll('li'); t.deepEqual($$('li', [$('ul'), $('ul')]), [...li]); }); test('counts elements', t => { t.plan(1); t.equal($$('ul li').length, 5); });