How to use testFails method in wpt

Best JavaScript code snippet using wpt

quail.js

Source:quail.js Github

copy

Full Screen

...143 quail.accessibilityResults[testName] = [ ];144 }145 if(testType === 'selector') {146 quail.html.find(quail.accessibilityTests[testName].selector).each(function() {147 quail.testFails(testName, $(this));148 });149 }150 if(testType === 'custom') {151 if(typeof quail.accessibilityTests[testName].callback === 'object' ||152 typeof quail.accessibilityTests[testName].callback === 'function') {153 quail.accessibilityTests[testName].callback(quail);154 }155 else {156 if(typeof quail[quail.accessibilityTests[testName].callback] !== 'undefined') {157 quail[quail.accessibilityTests[testName].callback]();158 }159 }160 }161 if(typeof quail[quail.testCallbacks[testType]] !== 'undefined') {162 quail[quail.testCallbacks[testType]](testName, quail.accessibilityTests[testName]);163 }164 });165 },166 167 /**168 * Helper function to determine if a string of text is even readable.169 * @todo - This will be added to in the future... we should also include170 * phonetic tests.171 */172 isUnreadable : function(text) {173 if(typeof text !== 'string') {174 return true;175 }176 return (text.trim().length) ? false : true;177 },178 /**179 * Read more about this function here: https://github.com/kevee/quail/wiki/Layout-versus-data-tables180 */181 isDataTable : function(table) {182 //If there are less than three rows, why do a table?183 if(table.find('tr').length < 3) {184 return false;185 }186 //If you are scoping a table, it's probably not being used for layout187 if(table.find('th[scope]').length) {188 return true;189 }190 var numberRows = table.find('tr:has(td)').length;191 //Check for odd cell spanning192 var spanCells = table.find('td[rowspan], td[colspan]');193 var isDataTable = true;194 if(spanCells.length) {195 var spanIndex = {};196 spanCells.each(function() {197 if(typeof spanIndex[$(this).index()] === 'undefined') {198 spanIndex[$(this).index()] = 0;199 }200 spanIndex[$(this).index()]++;201 });202 $.each(spanIndex, function(index, count) {203 if(count < numberRows) {204 isDataTable = false;205 }206 });207 }208 //If there are sub tables, but not in the same column row after row, this is a layout table209 var subTables = table.find('table');210 if(subTables.length) {211 var subTablesIndexes = {};212 subTables.each(function() {213 var parentIndex = $(this).parent('td').index();214 if(parentIndex !== false && typeof subTablesIndexes[parentIndex] === 'undefined') {215 subTablesIndexes[parentIndex] = 0;216 }217 subTablesIndexes[parentIndex]++;218 });219 $.each(subTablesIndexes, function(index, count) {220 if(count < numberRows) {221 isDataTable = false;222 }223 });224 }225 return isDataTable;226 },227 /**228 * Helper function to determine if a given URL is even valid.229 */230 validURL : function(url) {231 return (url.search(' ') === -1) ? true : false;232 },233 /**234 * Helper function to load a string from the jsonPath directory.235 */236 loadString : function(stringFile) {237 if(typeof quail.strings[stringFile] !== 'undefined') {238 return quail.strings[stringFile];239 }240 $.ajax({ url : quail.options.jsonPath + '/strings/' + stringFile + '.json',241 async: false,242 dataType : 'json',243 success : function(data) {244 quail.strings[stringFile] = data;245 }});246 return quail.strings[stringFile];247 },248 249 cleanString : function(string) {250 return string.toLowerCase().replace(/^\s\s*/, '');251 },252 253 /**254 * If a test uses the hasEventListener plugin, load it.255 * @todo - Allow this to be configured, although since we can256 * just check if it's there and if so, not load it, people could just257 * include the script.258 */259 loadHasEventListener : function() {260 if(typeof jQuery.hasEventListener !== 'undefined') {261 return;262 }263 $.ajax({url : quail.options.jsonPath + '/../../libs/jquery.hasEventListener/jquery.hasEventListener-2.0.3.min.js',264 async : false,265 dataType : 'script'266 });267 },268 /**269 * Loads the pixToEm jQuery plugin.270 */271 loadPixelToEm : function() {272 if(typeof jQuery.toPx !== 'undefined') {273 return;274 }275 $.ajax({url : quail.options.jsonPath + '/../../libs/jquery.pxToEm/pxem.jQuery.js',276 async : false,277 dataType : 'script'278 });279 },280 /**281 * Placeholder test - checks that an attribute or the content of an282 * element itself is not a placeholder (i.e. "click here" for links).283 */284 placeholderTest : function(testName, options) {285 quail.loadString('placeholders');286 quail.html.find(options.selector).each(function() {287 var text;288 if(typeof options.attribute !== 'undefined') {289 if(typeof $(this).attr(options.attribute) === 'undefined' ||290 (options.attribute === 'tabindex' &&291 !$(this).attr(options.attribute)292 )293 ) {294 quail.testFails(testName, $(this));295 return;296 }297 text = $(this).attr(options.attribute);298 }299 else {300 text = $(this).text();301 $(this).find('img[alt]').each(function() {302 text += $(this).attr('alt');303 });304 }305 if(typeof text === 'string') {306 text = quail.cleanString(text);307 var regex = /^([0-9]*)(k|kb|mb|k bytes|k byte)$/g;308 var regexResults = regex.exec(text.toLowerCase());309 if(regexResults && regexResults[0].length) {310 quail.testFails(testName, $(this));311 }312 else {313 if(options.empty && quail.isUnreadable(text)) {314 quail.testFails(testName, $(this));315 }316 else {317 if(quail.strings.placeholders.indexOf(text) > -1 ) {318 quail.testFails(testName, $(this));319 }320 }321 }322 }323 else {324 if(options.empty && typeof text !== 'number') {325 quail.testFails(testName, $(this));326 }327 }328 });329 },330 /**331 * Tests that a label element is close (DOM-wise) to it's target form element.332 */333 labelProximityTest : function(testName, options) {334 quail.html.find(options.selector).each(function() {335 var $label = quail.html.find('label[for=' + $(this).attr('id') + ']').first();336 if(!$label.length) {337 quail.testFails(testName, $(this));338 }339 if(!$(this).parent().is($label.parent())) {340 quail.testFails(testName, $(this));341 }342 });343 },344 345 /**346 * Test callback for color tests. This handles both WAI and WCAG347 * color contrast/luminosity.348 */349 colorTest : function(testName, options) {350 if(options.bodyForegroundAttribute && options.bodyBackgroundAttribute) {351 var $body = quail.html.find('body').clone(false, false);352 var foreground = $body.attr(options.bodyForegroundAttribute);353 var background = $body.attr(options.bodyBackgroundAttribute);354 if(typeof foreground === 'undefined') {355 foreground = 'rgb(0,0,0)';356 }357 if(typeof background === 'undefined') {358 foreground = 'rgb(255,255,255)';359 }360 $body.css('color', foreground);361 $body.css('background-color', background);362 if((options.algorithm === 'wcag' && !quail.colors.passesWCAG($body)) ||363 (options.algorithm === 'wai' && !quail.colors.passesWAI($body))) {364 quail.testFails(testName, $body);365 }366 }367 quail.html.find(options.selector).filter(quail.textSelector).each(function() {368 if(!quail.isUnreadable($(this).text()) &&369 (options.algorithm === 'wcag' && !quail.colors.passesWCAG($(this))) ||370 (options.algorithm === 'wai' && !quail.colors.passesWAI($(this)))) {371 quail.testFails(testName, $(this));372 }373 });374 },375 /**376 * Test callback for tests that look for script events377 * (like a mouse event has a keyboard event as well).378 */379 scriptEventTest : function(testName, options) {380 quail.loadHasEventListener();381 var $items = (typeof options.selector === 'undefined') ?382 quail.html.find('body').find('*') :383 quail.html.find(options.selector);384 $items.each(function() {385 var $element = $(this).get(0);386 if($(this).attr(options.searchEvent)) {387 if(typeof options.correspondingEvent === 'undefined' ||388 !$(this).attr(options.correspondingEvent)) {389 quail.testFails(testName, $(this));390 }391 }392 else {393 if($.hasEventListener($element, options.searchEvent.replace('on', '')) &&394 (typeof options.correspondingEvent === 'undefined' ||395 !$.hasEventListener($element, options.correspondingEvent.replace('on', '')))) {396 quail.testFails(testName, $(this));397 }398 }399 });400 },401 labelTest : function(testName, options) {402 quail.html.find(options.selector).each(function() {403 if((!$(this).parent('label').length ||404 !quail.containsReadableText($(this).parent('label'))) &&405 (!quail.html.find('label[for=' + $(this).attr('id') + ']').length ||406 !quail.containsReadableText(quail.html.find('label[for=' + $(this).attr('id') + ']')))) {407 quail.testFails(testName, $(this));408 }409 });410 },411 412 containsReadableText : function(element, children) {413 element = element.clone();414 element.find('option').remove();415 if(!quail.isUnreadable(element.text())) {416 return true;417 }418 if(!quail.isUnreadable(element.attr('alt'))) {419 return true;420 }421 if(children) {422 var readable = false;423 element.find('*').each(function() {424 if(quail.containsReadableText($(this), true)) {425 readable = true;426 }427 });428 if(readable) {429 return true;430 }431 }432 return false;433 },434 435 headerOrderTest : function(testName, options) {436 var current = parseInt(options.selector.substr(-1, 1), 10);437 var nextHeading = false;438 quail.html.find('h1, h2, h3, h4, h5, h6').each(function() {439 var number = parseInt($(this).get(0).tagName.substr(-1, 1), 10);440 if(nextHeading && (number - 1 > current || number + 1 < current)) {441 quail.testFails(testName, $(this));442 }443 if(number === current) {444 nextHeading = $(this);445 }446 if(nextHeading && number !== current) {447 nextHeading = false;448 }449 });450 },451 452 acronymTest : function(testName, acronymTag) {453 var predefined = { };454 var alreadyReported = { };455 quail.html.find(acronymTag + '[title]').each(function() {456 predefined[$(this).text().toUpperCase()] = $(this).attr('title');457 });458 quail.html.find('p, div, h1, h2, h3, h4, h5').each(function(){459 var $el = $(this);460 var words = $(this).text().split(' ');461 if(words.length > 1 && $(this).text().toUpperCase() !== $(this).text()) {462 $.each(words, function(index, word) {463 word = word.replace(/[^a-zA-Zs]/, '');464 if(word.toUpperCase() === word &&465 word.length > 1 &&466 typeof predefined[word.toUpperCase()] === 'undefined') {467 if(typeof alreadyReported[word.toUpperCase()] === 'undefined') {468 quail.testFails(testName, $el, {acronym : word.toUpperCase()});469 }470 alreadyReported[word.toUpperCase()] = word;471 }472 });473 }474 });475 },476 477 aAdjacentWithSameResourceShouldBeCombined : function() {478 quail.html.find('a').each(function() {479 if($(this).next('a').attr('href') === $(this).attr('href')) {480 quail.testFails('aAdjacentWithSameResourceShouldBeCombined', $(this));481 }482 });483 },484 485 aImgAltNotRepetative : function() {486 quail.html.find('a img[alt]').each(function() {487 if(quail.cleanString($(this).attr('alt')) === quail.cleanString($(this).parent('a').text())) {488 quail.testFails('aImgAltNotRepetative', $(this).parent('a'));489 }490 });491 },492 aLinksAreSeperatedByPrintableCharacters : function() {493 quail.html.find('a').each(function() {494 if($(this).next('a').length && quail.isUnreadable($(this).get(0).nextSibling.wholeText)) {495 quail.testFails('aLinksAreSeperatedByPrintableCharacters', $(this));496 }497 });498 },499 500 aLinkTextDoesNotBeginWithRedundantWord : function() {501 var redundant = quail.loadString('redundant');502 quail.html.find('a').each(function() {503 var $link = $(this);504 var text = '';505 if($(this).find('img[alt]').length) {506 text = text + $(this).find('img[alt]:first').attr('alt');507 }508 text = text + $(this).text();509 text = text.toLowerCase();510 $.each(redundant.link, function(index, phrase) {511 if(text.search(phrase) > -1) {512 quail.testFails('aLinkTextDoesNotBeginWithRedundantWord', $link);513 }514 });515 });516 },517 518 aMustContainText : function() {519 quail.html.find('a').each(function() {520 if(!quail.containsReadableText($(this), true) && 521 !(($(this).attr('name') || $(this).attr('id')) && !$(this).attr('href'))) {522 quail.testFails('aMustContainText', $(this));523 }524 });525 },526 527 aSuspiciousLinkText : function() {528 var suspiciousText = quail.loadString('suspicious_links');529 quail.html.find('a').each(function() {530 var text = $(this).text();531 $(this).find('img[alt]').each(function() {532 text = text + $(this).attr('alt');533 });534 if(suspiciousText.indexOf(quail.cleanString(text)) > -1) {535 quail.testFails('aSuspiciousLinkText', $(this));536 }537 });538 },539 540 blockquoteUseForQuotations : function() {541 quail.html.find('p').each(function() {542 if($(this).text().substr(0, 1).search(/[\'\"]/) > -1 &&543 $(this).text().substr(-1, 1).search(/[\'\"]/) > -1) {544 quail.testFails('blockquoteUseForQuotations', $(this));545 }546 });547 },548 documentAcronymsHaveElement : function() {549 quail.acronymTest('documentAcronymsHaveElement', 'acronym');550 },551 documentAbbrIsUsed : function() {552 quail.acronymTest('documentAbbrIsUsed', 'abbr');553 },554 documentTitleIsShort : function() {555 if(quail.html.find('head title:first').text().length > 150) {556 quail.testFails('documentTitleIsShort', quail.html.find('head title:first'));557 }558 },559 560 documentVisualListsAreMarkedUp : function() {561 var listQueues = [/\*/g, '<br>*', '&bull;', '&#8226'];562 quail.html.find('p, div, h1, h2, h3, h4, h5, h6').each(function() {563 var $element = $(this);564 $.each(listQueues, function(index, item) {565 if($element.text().split(item).length > 2) {566 quail.testFails('documentVisualListsAreMarkedUp', $element);567 }568 });569 });570 },571 572 documentValidatesToDocType : function() {573 if(typeof document.doctype === 'undefined') {574 return;575 }576 },577 578 documentIDsMustBeUnique : function() {579 var ids = [];580 quail.html.find('*[id]').each(function() {581 if(ids.indexOf($(this).attr('id')) >= 0) {582 quail.testFails('documentIDsMustBeUnique', $(this));583 }584 ids.push($(this).attr('id'));585 });586 },587 588 documentIsWrittenClearly : function() {589 quail.html.find(quail.textSelector).each(function() {590 var text = quail.textStatistics.cleanText($(this).text());591 if(Math.round((206.835 - (1.015 * quail.textStatistics.averageWordsPerSentence(text)) - (84.6 * quail.textStatistics.averageSyllablesPerWord(text)))) < 60) {592 quail.testFails('documentIsWrittenClearly', $(this));593 }594 });595 },596 597 documentLangIsISO639Standard : function() {598 var languages = quail.loadString('language_codes');599 var language = quail.html.find('html').attr('lang');600 if(!language) {601 return;602 }603 if(languages.indexOf(language) === -1) {604 quail.testFails('documentLangIsISO639Standard', quail.html.find('html'));605 }606 },607 608 doctypeProvided : function() {609 if($(quail.html.get(0).doctype).length === 0) {610 quail.testFails('doctypeProvided', quail.html.find('html'));611 }612 },613 appletContainsTextEquivalent : function() {614 quail.html.find('applet:not(applet[alt])').each(function() {615 if(quail.isUnreadable($(this).text())) {616 quail.testFails('appletContainsTextEquivalent', $(this));617 }618 });619 },620 621 documentStrictDocType : function() {622 if(!$(quail.html.get(0).doctype).length ||623 quail.html.get(0).doctype.systemId.indexOf('strict') === -1) {624 quail.testFails('documentStrictDocType', quail.html.find('html'));625 }626 },627 embedHasAssociatedNoEmbed : function() {628 if(quail.html.find('noembed').length) {629 return;630 }631 quail.html.find('embed').each(function() {632 quail.testFails('embedHasAssociatedNoEmbed', $(this));633 });634 },635 636 emoticonsExcessiveUse : function() {637 var emoticons = quail.loadString('emoticons');638 var count = 0;639 quail.html.find('p, div, h1, h2, h3, h4, h5, h6').each(function() {640 var $element = $(this);641 $.each($element.text().split(' '), function(index, word) {642 if(emoticons.indexOf(word) > -1) {643 count++;644 }645 if(count > 4) {646 return;647 }648 });649 if(count > 4) {650 quail.testFails('emoticonsExcessiveUse', $element);651 }652 });653 },654 655 emoticonsMissingAbbr : function() {656 var emoticons = quail.loadString('emoticons');657 quail.html.find('p, div, h1, h2, h3, h4, h5, h6').each(function() {658 var $element = $(this);659 var $clone = $element.clone();660 $clone.find('abbr, acronym').each(function() {661 $(this).remove();662 });663 $.each($clone.text().split(' '), function(index, word) {664 if(emoticons.indexOf(word) > -1) {665 quail.testFails('emoticonsMissingAbbr', $element);666 }667 });668 });669 },670 671 formWithRequiredLabel : function() {672 var redundant = quail.loadString('redundant');673 var lastStyle, currentStyle = false;674 redundant.required[redundant.required.indexOf('*')] = /\*/g;675 quail.html.find('label').each(function() {676 var text = $(this).text().toLowerCase();677 var $label = $(this);678 $.each(redundant.required, function(index, word) {679 if(text.search(word) >= 0 && !quail.html.find('#' + $label.attr('for')).attr('aria-required')) {680 quail.testFails('formWithRequiredLabel', $label);681 }682 });683 currentStyle = $label.css('color') + $label.css('font-weight') + $label.css('background-color');684 if(lastStyle && currentStyle !== lastStyle) {685 quail.testFails('formWithRequiredLabel', $label);686 }687 lastStyle = currentStyle;688 });689 },690 691 headersUseToMarkSections : function() {692 quail.html.find('p').each(function() {693 var $paragraph = $(this);694 $paragraph.find('strong:first, em:first, i:first, b:first').each(function() {695 if($paragraph.text() === $(this).text()) {696 quail.testFails('headersUseToMarkSections', $paragraph);697 }698 });699 });700 },701 imgAltIsDifferent : function() {702 quail.html.find('img[alt][src]').each(function() {703 if($(this).attr('src') === $(this).attr('alt') || $(this).attr('src').split('/').pop() === $(this).attr('alt')) {704 quail.testFails('imgAltIsDifferent', $(this));705 }706 });707 },708 imgAltIsTooLong : function() {709 quail.html.find('img[alt]').each(function() {710 if($(this).attr('alt').length > 100) {711 quail.testFails('imgAltIsTooLong', $(this));712 }713 });714 },715 716 imgAltTextNotRedundant : function() {717 var altText = {};718 quail.html.find('img[alt]').each(function() {719 if(typeof altText[$(this).attr('alt')] === 'undefined') {720 altText[$(this).attr('alt')] = $(this).attr('src');721 }722 else {723 if(altText[$(this).attr('alt')] !== $(this).attr('src')) {724 quail.testFails('imgAltTextNotRedundant', $(this));725 }726 }727 });728 },729 730 inputCheckboxRequiresFieldset : function() {731 quail.html.find(':checkbox').each(function() {732 if(!$(this).parents('fieldset').length) {733 quail.testFails('inputCheckboxRequiresFieldset', $(this));734 }735 });736 },737 inputImageAltIsNotFileName : function() {738 quail.html.find('input[type=image][alt]').each(function() {739 if($(this).attr('src') === $(this).attr('alt')) {740 quail.testFails('inputImageAltIsNotFileName', $(this));741 }742 });743 },744 inputImageAltIsShort : function() {745 quail.html.find('input[type=image]').each(function() {746 if($(this).attr('alt').length > 100) {747 quail.testFails('inputImageAltIsShort', $(this));748 }749 });750 },751 752 inputImageAltNotRedundant : function() {753 var redundant = quail.loadString('redundant');754 quail.html.find('input[type=image][alt]').each(function() {755 if(redundant.inputImage.indexOf(quail.cleanString($(this).attr('alt'))) > -1) {756 quail.testFails('inputImageAltNotRedundant', $(this));757 }758 });759 },760 imgImportantNoSpacerAlt : function() {761 quail.html.find('img[alt]').each(function() {762 var width = ($(this).width()) ? $(this).width() : parseInt($(this).attr('width'), 10);763 var height = ($(this).height()) ? $(this).height() : parseInt($(this).attr('height'), 10);764 if(quail.isUnreadable($(this).attr('alt').trim()) &&765 $(this).attr('alt').length > 0 &&766 width > 50 &&767 height > 50) {768 quail.testFails('imgImportantNoSpacerAlt', $(this));769 }770 });771 },772 773 imgNonDecorativeHasAlt : function() {774 quail.html.find('img[alt]').each(function() {775 if(quail.isUnreadable($(this).attr('alt')) &&776 ($(this).width() > 100 || $(this).height() > 100)) {777 quail.testFails('imgNonDecorativeHasAlt', $(this));778 }779 });780 },781 imgAltNotEmptyInAnchor : function() {782 quail.html.find('a img').each(function() {783 if(quail.isUnreadable($(this).attr('alt')) &&784 quail.isUnreadable($(this).parent('a:first').text())) {785 quail.testFails('imgAltNotEmptyInAnchor', $(this));786 }787 });788 },789 imgHasLongDesc : function() {790 quail.html.find('img[longdesc]').each(function() {791 if($(this).attr('longdesc') === $(this).attr('alt') ||792 !quail.validURL($(this).attr('longdesc'))) {793 quail.testFails('imgHasLongDesc', $(this));794 }795 });796 },797 imgMapAreasHaveDuplicateLink : function() {798 var links = { };799 quail.html.find('a').each(function() {800 links[$(this).attr('href')] = $(this).attr('href');801 });802 quail.html.find('img[usemap]').each(function() {803 var $image = $(this);804 var $map = quail.html.find($image.attr('usemap'));805 if(!$map.length) {806 $map = quail.html.find('map[name="' + $image.attr('usemap').replace('#', '') + '"]');807 }808 if($map.length) {809 $map.find('area').each(function() {810 if(typeof links[$(this).attr('href')] === 'undefined') {811 quail.testFails('imgMapAreasHaveDuplicateLink', $image);812 }813 });814 }815 });816 },817 imgGifNoFlicker : function() {818 quail.html.find('img[src$=".gif"]').each(function() {819 var $image = $(this);820 $.ajax({url : $image.attr('src'),821 async : false,822 dataType : 'text',823 success : function(data) {824 if(data.search('NETSCAPE2.0') !== -1) {825 quail.testFails('imgGifNoFlicker', $image);826 }827 }});828 });829 },830 831 imgWithMathShouldHaveMathEquivalent : function() {832 quail.html.find('img:not(img:has(math), img:has(tagName))').each(function() {833 if(!$(this).parent().find('math').length) {834 quail.testFails('imgWithMathShouldHaveMathEquivalent', $(this));835 }836 });837 },838 839 labelMustBeUnique : function() {840 var labels = { };841 quail.html.find('label[for]').each(function() {842 if(typeof labels[$(this).attr('for')] !== 'undefined') {843 quail.testFails('labelMustBeUnique', $(this));844 }845 labels[$(this).attr('for')] = $(this).attr('for');846 });847 },848 849 labelsAreAssignedToAnInput : function() {850 quail.html.find('label').each(function() {851 if(!$(this).attr('for')) {852 quail.testFails('labelsAreAssignedToAnInput', $(this));853 }854 else {855 if(!quail.html.find('#' + $(this).attr('for')).length ||856 !quail.html.find('#' + $(this).attr('for')).is('input, select, textarea')) {857 quail.testFails('labelsAreAssignedToAnInput', $(this));858 }859 }860 });861 },862 863 listNotUsedForFormatting : function() {864 quail.html.find('ol, ul').each(function() {865 if($(this).find('li').length < 2) {866 quail.testFails('listNotUsedForFormatting', $(this));867 }868 });869 },870 871 paragarphIsWrittenClearly : function() {872 quail.html.find('p').each(function() {873 var text = quail.textStatistics.cleanText($(this).text());874 if(Math.round((206.835 - (1.015 * quail.textStatistics.averageWordsPerSentence(text)) - (84.6 * quail.textStatistics.averageSyllablesPerWord(text)))) < 60) {875 quail.testFails('paragarphIsWrittenClearly', $(this));876 }877 });878 },879 880 siteMap : function() {881 var mapString = quail.loadString('site_map');882 var set = true;883 quail.html.find('a').each(function() {884 var text = $(this).text().toLowerCase();885 $.each(mapString, function(index, string) {886 if(text.search(string) > -1) {887 set = false;888 return;889 }890 });891 if(set === false) {892 return;893 }894 });895 if(set) {896 quail.testFails('siteMap', quail.html.find('body'));897 }898 },899 pNotUsedAsHeader : function() {900 var priorStyle = { };901 quail.html.find('p').each(function() {902 if($(this).text().search('.') < 1) {903 var $paragraph = $(this);904 $.each(quail.suspectPHeaderTags, function(index, tag) {905 if($paragraph.find(tag).length) {906 $paragraph.find(tag).each(function() {907 if($(this).text().trim() === $paragraph.text().trim()) {908 quail.testFails('pNotUsedAsHeader', $paragraph);909 }910 });911 }912 });913 $.each(quail.suspectPCSSStyles, function(index, style) {914 if(typeof priorStyle[style] !== 'undefined' &&915 priorStyle[style] !== $paragraph.css(style)) {916 quail.testFails('pNotUsedAsHeader', $paragraph);917 }918 priorStyle[style] = $paragraph.css(style);919 });920 if($paragraph.css('font-weight') === 'bold') {921 quail.testFails('pNotUsedAsHeader', $paragraph);922 }923 }924 });925 },926 927 preShouldNotBeUsedForTabularLayout : function() {928 quail.html.find('pre').each(function() {929 var rows = $(this).text().split(/[\n\r]+/);930 if(rows.length > 1 && $(this).text().search(/\t/) > -1) {931 quail.testFails('preShouldNotBeUsedForTabularLayout', $(this));932 }933 });934 },935 936 selectJumpMenu : function() {937 if(quail.html.find('select').length === 0) {938 return;939 }940 quail.loadHasEventListener();941 942 quail.html.find('select').each(function() {943 if(($(this).parent('form').find(':submit').length === 0 ) &&944 ($.hasEventListener($(this), 'change') ||945 $(this).attr('onchange'))) {946 quail.testFails('selectJumpMenu', $(this));947 }948 });949 },950 tableHeaderLabelMustBeTerse : function() {951 quail.html.find('th, table tr:first td').each(function() {952 if($(this).text().length > 20 &&953 (!$(this).attr('abbr') || $(this).attr('abbr').length > 20)) {954 quail.testFails('tableHeaderLabelMustBeTerse', $(this));955 }956 });957 },958 tabIndexFollowsLogicalOrder : function() {959 var index = 0;960 quail.html.find('[tabindex]').each(function() {961 if(parseInt($(this).attr('tabindex'), 10) >= 0 &&962 parseInt($(this).attr('tabindex'), 10) !== index + 1) {963 quail.testFails('tabIndexFollowsLogicalOrder', $(this));964 }965 index++;966 });967 },968 969 tableLayoutDataShouldNotHaveTh : function() {970 quail.html.find('table:has(th)').each(function() {971 if(!quail.isDataTable($(this))) {972 quail.testFails('tableLayoutDataShouldNotHaveTh', $(this));973 }974 });975 },976 977 tableLayoutHasNoSummary : function() {978 quail.html.find('table[summary]').each(function() {979 if(!quail.isDataTable($(this)) && !quail.isUnreadable($(this).attr('summary'))) {980 quail.testFails('tableLayoutHasNoSummary', $(this));981 }982 });983 },984 tableLayoutHasNoCaption : function() {985 quail.html.find('table:has(caption)').each(function() {986 if(!quail.isDataTable($(this))) {987 quail.testFails('tableLayoutHasNoCaption', $(this));988 }989 });990 },991 tableLayoutMakesSenseLinearized : function() {992 quail.html.find('table').each(function() {993 if(!quail.isDataTable($(this))) {994 quail.testFails('tableLayoutMakesSenseLinearized', $(this));995 }996 });997 },998 999 tableNotUsedForLayout : function() {1000 quail.html.find('table').each(function() {1001 if(!quail.isDataTable($(this))) {1002 quail.testFails('tableNotUsedForLayout', $(this));1003 }1004 });1005 },1006 1007 tableSummaryDoesNotDuplicateCaption : function() {1008 quail.html.find('table[summary]:has(caption)').each(function() {1009 if(quail.cleanString($(this).attr('summary')) === quail.cleanString($(this).find('caption:first').text())) {1010 quail.testFails('tableSummaryDoesNotDuplicateCaption', $(this));1011 }1012 });1013 },1014 1015 tableSummaryIsNotTooLong : function() {1016 quail.html.find('table[summary]').each(function() {1017 if($(this).attr('summary').trim().length > 100) {1018 quail.testFails('tableSummaryIsNotTooLong', $(this));1019 }1020 });1021 },1022 tableUsesAbbreviationForHeader : function() {1023 quail.html.find('th:not(th[abbr])').each(function() {1024 if($(this).text().length > 20) {1025 quail.testFails('tableUsesAbbreviationForHeader', $(this));1026 }1027 });1028 },1029 1030 tableUseColGroup : function() {1031 quail.html.find('table').each(function() {1032 if(quail.isDataTable($(this)) && !$(this).find('colgroup').length) {1033 quail.testFails('tableUseColGroup', $(this));1034 }1035 });1036 },1037 1038 tableUsesScopeForRow : function() {1039 quail.html.find('table').each(function() {1040 $(this).find('td:first-child').each(function() {1041 var $next = $(this).next('td');1042 if(($(this).css('font-weight') === 'bold' && $next.css('font-weight') !== 'bold') ||1043 ($(this).find('strong').length && !$next.find('strong').length)) {1044 quail.testFails('tableUsesScopeForRow', $(this));1045 }1046 });1047 $(this).find('td:last-child').each(function() {1048 var $prev = $(this).prev('td');1049 if(($(this).css('font-weight') === 'bold' && $prev.css('font-weight') !== 'bold') ||1050 ($(this).find('strong').length && !$prev.find('strong').length)) {1051 quail.testFails('tableUsesScopeForRow', $(this));1052 }1053 });1054 });1055 },1056 1057 tableWithMoreHeadersUseID : function() {1058 quail.html.find('table:has(th)').each(function() {1059 var $table = $(this);1060 var rows = 0;1061 $table.find('tr').each(function() {1062 if($(this).find('th').length) {1063 rows++;1064 }1065 if(rows > 1 && !$(this).find('th[id]').length) {1066 quail.testFails('tableWithMoreHeadersUseID', $table);1067 }1068 });1069 });1070 },1071 1072 textIsNotSmall : function() {1073 quail.loadPixelToEm();1074 quail.html.find(quail.textSelector).each(function() {1075 var fontSize = $(this).css('font-size');1076 if(fontSize.search('em') > 0) {1077 fontSize = $(this).toPx({scope : quail.html});1078 }1079 fontSize = parseInt(fontSize.replace('px', ''), 10);1080 if(fontSize < 10) {1081 quail.testFails('textIsNotSmall', $(this));1082 }1083 });1084 },1085 1086 videosEmbeddedOrLinkedNeedCaptions : function() {1087 quail.html.find('a').each(function() {1088 var $link = $(this);1089 $.each(quail.videoServices, function(type, callback) {1090 if(callback.isVideo($link.attr('href'))) {1091 callback.hasCaptions(function(hasCaptions) {1092 if(!hasCaptions) {1093 quail.testFails('videosEmbeddedOrLinkedNeedCaptions', $link);1094 }1095 });1096 }1097 });1098 });1099 },1100 1101 tabularDataIsInTable : function() {1102 quail.html.find('pre').each(function() {1103 if($(this).html().search('\t') >= 0) {1104 quail.testFails('tabularDataIsInTable', $(this));1105 }1106 });1107 }1108 };1109 /**1110 * Utility object for statistics, like average, variance, etc.1111 */1112 quail.statistics = {1113 1114 setDecimal : function( num, numOfDec ){1115 var pow10s = Math.pow( 10, numOfDec || 0 );1116 return ( numOfDec ) ? Math.round( pow10s * num ) / pow10s : num;1117 },1118 ...

Full Screen

Full Screen

model.populate.divergent.test.js

Source:model.populate.divergent.test.js Github

copy

Full Screen

...67 }68 function testOk(fn) {69 test(assert.ifError.bind(assert), fn);70 }71 function testFails(fn) {72 test(function(err) {73 assert.ok(err instanceof DivergentArrayError, 'non-divergent error: ' + err);74 assert.ok(/\sarray/.test(err.message));75 }, fn);76 }77 describe('from match', function() {78 testFails(function(cb) {79 M.findOne().populate({ path: 'array', match: { name: 'one' } }).exec(cb);80 });81 });82 describe('from skip', function() {83 describe('2', function() {84 testFails(function(cb) {85 M.findOne().populate({ path: 'array', options: { skip: 2 } }).exec(cb);86 });87 });88 describe('0', function() {89 testOk(function(cb) {90 M.findOne().populate({ path: 'array', options: { skip: 0 } }).exec(cb);91 });92 });93 });94 describe('from limit', function() {95 describe('0', function() {96 testFails(function(cb) {97 M.findOne().populate({ path: 'array', options: { limit: 0 } }).exec(cb);98 });99 });100 describe('1', function() {101 testFails(function(cb) {102 M.findOne().populate({ path: 'array', options: { limit: 1 } }).exec(cb);103 });104 });105 });106 describe('from deselected _id', function() {107 describe('using string and only -_id', function() {108 testFails(function(cb) {109 M.findOne().populate({ path: 'array', select: '-_id' }).exec(cb);110 });111 });112 describe('using string', function() {113 testFails(function(cb) {114 M.findOne().populate({ path: 'array', select: 'name -_id' }).exec(cb);115 });116 });117 describe('using object and only _id: 0', function() {118 testFails(function(cb) {119 M.findOne().populate({ path: 'array', select: { _id: 0 } }).exec(cb);120 });121 });122 describe('using object', function() {123 testFails(function(cb) {124 M.findOne().populate({ path: 'array', select: { _id: 0, name: 1 } }).exec(cb);125 });126 });127 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options);5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var options = {13};14var wpt = new WebPageTest('www.webpagetest.org', options);15}, function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('webpagetest');23var options = {24};25var wpt = new WebPageTest('www.webpagetest.org', options);26}, function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('webpagetest');34var options = {35};36var wpt = new WebPageTest('www.webpagetest.org', options);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2 if (error) {3 console.log(error);4 } else {5 console.log(data);6 }7});8var wpt = require('wpt.js');9 if (error) {10 console.log(error);11 } else {12 console.log(data);13 }14});15var wpt = require('wpt.js');16 if (error) {17 console.log(error);18 } else {19 console.log(data);20 }21});22var wpt = require('wpt.js');23 if (error) {24 console.log(error);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt.js');30 if (error) {31 console.log(error);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt.js');37 if (error) {38 console.log(error);39 } else {40 console.log(data);41 }42});43var wpt = require('wpt.js');44 if (error) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2 if (err) {3 console.log(err);4 }5 else {6 console.log(data);7 }8});9wpt.testFails(url, options, callback)10 * `location` - Location to run test from (default: `Dulles:Chrome`)11 * `runs` - Number of test runs (default: `1`)12 * `firstViewOnly` - Only test the first view (default: `false`)13 * `pollResults` - Poll for results every `pollResults` seconds (default: `10`)14 * `timeout` - Timeout after `timeout` seconds (default: `30`)15 * `function(err, data)`16wpt.testSucceeds(url, options, callback)17 * `location` - Location to run test from (default: `Dulles:Chrome`)18 * `runs` - Number of test runs (default: `1`)19 * `firstViewOnly` - Only test the first view (default: `false`)20 * `pollResults` - Poll for results every `pollResults` seconds (default: `10`)21 * `timeout` - Timeout after `timeout` seconds (default: `30`)22 * `function(err, data)`23wpt.getTestResults(testId, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.testFails(options, function(err, data) {5 if(err){6 console.log('error: ', err);7 } else {8 console.log('data: ', data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.testResults(options, function(err, data) {15 if(err){16 console.log('error: ', err);17 } else {18 console.log('data: ', data);19 }20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5f5fa8c8e5f5fa8c8e5f5fa8c8e5f5f5');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful