it('.hasDescendantMatching', function () { ensure(el).hasDescendantMatching('span'); ensure(el).hasDescendantMatching('i'); ensure(el).hasDescendantMatching('.test-class'); ensure(el).hasDescendantMatching('.test-class.other-class'); assertThrows(function () { ensure(el).hasDescendantMatching('div'); }, "Expected <div> to have a descendant matching the query 'div'."); assertThrows(function () { ensure(el).hasDescendantMatching('.absent'); }, "Expected <div> to have a descendant matching the query '.absent'."); });
it('.hasAttribute', function () { ensure(el.firstElementChild).hasAttribute('id'); ensure(el.firstElementChild).hasAttribute('id').withValue('0'); assertThrows(function () { ensure(el.firstElementChild).hasAttribute('invalid'); }, "Expected <span id=\"0\" class=\"test-class other-class\"> " + "to have an attribute named 'invalid'."); assertThrows(function () { ensure(el.firstElementChild).hasAttribute('id').withValue('2'); }, "Expected <span id=\"0\" class=\"test-class other-class\"> " + "to have an attribute 'id' with value \"2\", " + "actual value was \"0\"."); });
function assertThrows(f, msg) { try { f(); } catch (e) { ensure(e + '').named('message').equals('Error: ' + msg); return; } throw new Error('expected assertion failure with message: \'' + msg + '\''); }
assertThrows(function () { ensure(el).eachChildElement().hasTagName('i'); },
it('.eachChildElement', function () { ensure(el).eachChildElement().hasTagName('span'); assertThrows(function () { ensure(el).eachChildElement().hasTagName('i'); }, "Expected child 0 of <div> to have a tag name of 'I', " + "actual tag name was 'SPAN'."); });
assertThrows(function () { ensure(el.firstElementChild).doesNotHaveClass('test-class'); },
it('.doesNotHaveClass', function () { ensure(el.firstElementChild).doesNotHaveClass('invalid'); assertThrows(function () { ensure(el.firstElementChild).doesNotHaveClass('test-class'); }, "Expected <span id=\"0\" class=\"test-class other-class\"> to not have class 'test-class'."); });
assertThrows(function () { ensure(el.firstElementChild).hasClass('invalid'); },
assertThrows(function () { ensure(el.firstElementChild).hasAttribute('id').withValue('2'); },
assertThrows(function () { ensure(el.firstElementChild).hasAttribute('invalid'); },
assertThrows(function () { ensure(el).hasDescendantMatching('.absent'); },
assertThrows(function () { ensure(el).hasChildCount(0); },
it('.hasChildCount', function () { ensure(el).hasChildCount(1); assertThrows(function () { ensure(el).hasChildCount(0); }, "Expected <div> to have 0 children, actual number was 1."); });
it('.hasTagName', function () { ensure(document.body).hasTagName('body'); ensure(el).hasTagName('div'); });
it('.isElement', function () { ensure(document.body).isElement(); ensure(el).isElement(); });