Best JavaScript code snippet using ava
crystal.js
Source:crystal.js
1/*2Language: Crystal3Author: TSUYUSATO Kitsune <make.just.on@gmail.com>4*/5function(hljs) {6 var NUM_SUFFIX = '(_[uif](8|16|32|64))?';7 var CRYSTAL_IDENT_RE = '[a-zA-Z_]\\w*[!?=]?';8 var RE_STARTER = '!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|' +9 '>>|>|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';10 var CRYSTAL_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\][=?]?';11 var CRYSTAL_KEYWORDS = {12 keyword:13 'abstract alias as as? asm begin break case class def do else elsif end ensure enum extend for fun if ' +14 'include instance_sizeof is_a? lib macro module next nil? of out pointerof private protected rescue responds_to? ' +15 'return require select self sizeof struct super then type typeof union uninitialized unless until when while with yield ' +16 '__DIR__ __END_LINE__ __FILE__ __LINE__',17 literal: 'false nil true'18 };19 var SUBST = {20 className: 'subst',21 begin: '#{', end: '}',22 keywords: CRYSTAL_KEYWORDS23 };24 var EXPANSION = {25 className: 'template-variable',26 variants: [27 {begin: '\\{\\{', end: '\\}\\}'},28 {begin: '\\{%', end: '%\\}'}29 ],30 keywords: CRYSTAL_KEYWORDS31 };32 function recursiveParen(begin, end) {33 var34 contains = [{begin: begin, end: end}];35 contains[0].contains = contains;36 return contains;37 }38 var STRING = {39 className: 'string',40 contains: [hljs.BACKSLASH_ESCAPE, SUBST],41 variants: [42 {begin: /'/, end: /'/},43 {begin: /"/, end: /"/},44 {begin: /`/, end: /`/},45 {begin: '%w?\\(', end: '\\)', contains: recursiveParen('\\(', '\\)')},46 {begin: '%w?\\[', end: '\\]', contains: recursiveParen('\\[', '\\]')},47 {begin: '%w?{', end: '}', contains: recursiveParen('{', '}')},48 {begin: '%w?<', end: '>', contains: recursiveParen('<', '>')},49 {begin: '%w?/', end: '/'},50 {begin: '%w?%', end: '%'},51 {begin: '%w?-', end: '-'},52 {begin: '%w?\\|', end: '\\|'},53 {begin: /<<-\w+$/, end: /^\s*\w+$/},54 ],55 relevance: 0,56 };57 var Q_STRING = {58 className: 'string',59 variants: [60 {begin: '%q\\(', end: '\\)', contains: recursiveParen('\\(', '\\)')},61 {begin: '%q\\[', end: '\\]', contains: recursiveParen('\\[', '\\]')},62 {begin: '%q{', end: '}', contains: recursiveParen('{', '}')},63 {begin: '%q<', end: '>', contains: recursiveParen('<', '>')},64 {begin: '%q/', end: '/'},65 {begin: '%q%', end: '%'},66 {begin: '%q-', end: '-'},67 {begin: '%q\\|', end: '\\|'},68 {begin: /<<-'\w+'$/, end: /^\s*\w+$/},69 ],70 relevance: 0,71 };72 var REGEXP = {73 begin: '(' + RE_STARTER + ')\\s*',74 contains: [75 {76 className: 'regexp',77 contains: [hljs.BACKSLASH_ESCAPE, SUBST],78 variants: [79 {begin: '//[a-z]*', relevance: 0},80 {begin: '/', end: '/[a-z]*'},81 {begin: '%r\\(', end: '\\)', contains: recursiveParen('\\(', '\\)')},82 {begin: '%r\\[', end: '\\]', contains: recursiveParen('\\[', '\\]')},83 {begin: '%r{', end: '}', contains: recursiveParen('{', '}')},84 {begin: '%r<', end: '>', contains: recursiveParen('<', '>')},85 {begin: '%r/', end: '/'},86 {begin: '%r%', end: '%'},87 {begin: '%r-', end: '-'},88 {begin: '%r\\|', end: '\\|'},89 ]90 }91 ],92 relevance: 093 };94 var REGEXP2 = {95 className: 'regexp',96 contains: [hljs.BACKSLASH_ESCAPE, SUBST],97 variants: [98 {begin: '%r\\(', end: '\\)', contains: recursiveParen('\\(', '\\)')},99 {begin: '%r\\[', end: '\\]', contains: recursiveParen('\\[', '\\]')},100 {begin: '%r{', end: '}', contains: recursiveParen('{', '}')},101 {begin: '%r<', end: '>', contains: recursiveParen('<', '>')},102 {begin: '%r/', end: '/'},103 {begin: '%r%', end: '%'},104 {begin: '%r-', end: '-'},105 {begin: '%r\\|', end: '\\|'},106 ],107 relevance: 0108 };109 var ATTRIBUTE = {110 className: 'meta',111 begin: '@\\[', end: '\\]',112 contains: [113 hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'meta-string'})114 ]115 };116 var CRYSTAL_DEFAULT_CONTAINS = [117 EXPANSION,118 STRING,119 Q_STRING,120 REGEXP,121 REGEXP2,122 ATTRIBUTE,123 hljs.HASH_COMMENT_MODE,124 {125 className: 'class',126 beginKeywords: 'class module struct', end: '$|;',127 illegal: /=/,128 contains: [129 hljs.HASH_COMMENT_MODE,130 hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?'}),131 {begin: '<'} // relevance booster for inheritance132 ]133 },134 {135 className: 'class',136 beginKeywords: 'lib enum union', end: '$|;',137 illegal: /=/,138 contains: [139 hljs.HASH_COMMENT_MODE,140 hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?'}),141 ],142 relevance: 10143 },144 {145 className: 'function',146 beginKeywords: 'def', end: /\B\b/,147 contains: [148 hljs.inherit(hljs.TITLE_MODE, {149 begin: CRYSTAL_METHOD_RE,150 endsParent: true151 })152 ]153 },154 {155 className: 'function',156 beginKeywords: 'fun macro', end: /\B\b/,157 contains: [158 hljs.inherit(hljs.TITLE_MODE, {159 begin: CRYSTAL_METHOD_RE,160 endsParent: true161 })162 ],163 relevance: 5164 },165 {166 className: 'symbol',167 begin: hljs.UNDERSCORE_IDENT_RE + '(\\!|\\?)?:',168 relevance: 0169 },170 {171 className: 'symbol',172 begin: ':',173 contains: [STRING, {begin: CRYSTAL_METHOD_RE}],174 relevance: 0175 },176 {177 className: 'number',178 variants: [179 { begin: '\\b0b([01_]*[01])' + NUM_SUFFIX },180 { begin: '\\b0o([0-7_]*[0-7])' + NUM_SUFFIX },181 { begin: '\\b0x([A-Fa-f0-9_]*[A-Fa-f0-9])' + NUM_SUFFIX },182 { begin: '\\b(([0-9][0-9_]*[0-9]|[0-9])(\\.[0-9_]*[0-9])?([eE][+-]?[0-9_]*[0-9])?)' + NUM_SUFFIX}183 ],184 relevance: 0185 }186 ];187 SUBST.contains = CRYSTAL_DEFAULT_CONTAINS;188 EXPANSION.contains = CRYSTAL_DEFAULT_CONTAINS.slice(1); // without EXPANSION189 return {190 aliases: ['cr'],191 lexemes: CRYSTAL_IDENT_RE,192 keywords: CRYSTAL_KEYWORDS,193 contains: CRYSTAL_DEFAULT_CONTAINS194 };...
ScrapeData.js
Source:ScrapeData.js
...24 var phone = {};25 phone.id = agent.url.split(/\//).pop();26 phone.name = body.find('h2').text().trim();27 phone.description = body.find('.description').text().trim();28 phone.availability = c1.find('table:nth-child(1) th:contains("Availability")+td').text().trim().split(/\s*\n\s*/),29 phone.battery = {30 type: c1.find('table:nth-child(2) th:contains("Type")+td').text(),31 talkTime: c1.find('table:nth-child(2) th:contains("Talk time")+td').text(),32 standbyTime: c1.find('table:nth-child(2) th:contains("Standby time")+td').text()33 };34 phone.storage = {35 ram: c1.find('table:nth-child(3) th:contains("RAM")+td').text(),36 flash: c1.find('table:nth-child(3) th:contains("Internal storage")+td').text()37 };38 phone.connectivity = {39 cell: c1.find('table:nth-child(4) th:contains("Network support")+td').text(),40 wifi: c1.find('table:nth-child(4) th:contains("WiFi")+td').text(),41 bluetooth: c1.find('table:nth-child(4) th:contains("Bluetooth")+td').text(),42 infrared: boolean(c1.find('table:nth-child(4) th:contains("Infrared")+td img').attr('src')),43 gps: boolean(c1.find('table:nth-child(4) th:contains("GPS")+td img').attr('src'))44 };45 phone.android = {46 os: c2.find('table:nth-child(1) th:contains("OS Version")+td').text(),47 ui: c2.find('table:nth-child(1) th:contains("UI")+td').text()48 };49 phone.sizeAndWeight = {50 dimensions: c2.find('table:nth-child(2) th:contains("Dimensions")+td').text().trim().split(/\s*\n\s*/),51 weight: c2.find('table:nth-child(2) th:contains("Weight")+td').text().trim()52 };53 phone.display = {54 screenSize: c2.find('table:nth-child(3) th:contains("Screen size")+td').text(),55 screenResolution: c2.find('table:nth-child(3) th:contains("Screen resolution")+td').text(),56 touchScreen: boolean(c2.find('table:nth-child(3) th:contains("Touch screen")+td img').attr('src'))57 };58 phone.hardware = {59 fmRadio: boolean(c2.find('table:nth-child(4) th:contains("FM Radio")+td img').attr('src')),60 physicalKeyboard: c2.find('table:nth-child(4) th:contains("Physical keyboard")+td img').attr('src'),61 accelerometer: boolean(c2.find('table:nth-child(4) th:contains("Accelerometer")+td img').attr('src')),62 cpu: c2.find('table:nth-child(4) th:contains("CPU")+td').text(),63 usb: c2.find('table:nth-child(4) th:contains("USB")+td').text(),64 audioJack: c2.find('table:nth-child(4) th:contains("Audio / headphone jack")+td').text()65 };66 phone.camera= {67 primary: c2.find('table:nth-child(5) th:contains("Primary")+td').text(),68 features: c2.find('table:nth-child(5) th:contains("Features")+td').text().trim().split(/\s*\n\s*/)69 };70 phone.additionalFeatures = c2.find('table:nth-child(6) td').text();71 phone.images = [];72 body.find('#thumbs img').each(function(){73 var imgUrl = 'http://www.google.com' + jquery(this).attr('src');74 phone.images.push({75 small: imgUrl,76 large: imgUrl.replace(/\/small$/, '/large')77 });78 });79 fs.writeSync(fs.openSync(baseDir + phone.id + '.json', 'w'), JSON.stringify(phone));80 } else {81 var age = 0;82 body.find('ul.phonelist li.list').each(function(a){...
ruby.js
Source:ruby.js
1/*2Language: Ruby3Author: Anton Kovalyov <anton@kovalyov.net>4Contributors: Peter Leonov <gojpeg@yandex.ru>, Vasily Polovnyov <vast@whiteants.net>, Loren Segal <lsegal@soen.ca>, Pascal Hurni <phi@ruby-reactive.org>, Cedric Sohrauer <sohrauer@googlemail.com>5Category: common6*/7function(hljs) {8 var RUBY_METHOD_RE = '[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?';9 var RUBY_KEYWORDS =10 'and false then defined module in return redo if BEGIN retry end for true self when ' +11 'next until do begin unless END rescue nil else break undef not super class case ' +12 'require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor';13 var YARDOCTAG = {14 className: 'doctag',15 begin: '@[A-Za-z]+'16 };17 var IRB_OBJECT = {18 className: 'value',19 begin: '#<', end: '>'20 };21 var COMMENT_MODES = [22 hljs.COMMENT(23 '#',24 '$',25 {26 contains: [YARDOCTAG]27 }28 ),29 hljs.COMMENT(30 '^\\=begin',31 '^\\=end',32 {33 contains: [YARDOCTAG],34 relevance: 1035 }36 ),37 hljs.COMMENT('^__END__', '\\n$')38 ];39 var SUBST = {40 className: 'subst',41 begin: '#\\{', end: '}',42 keywords: RUBY_KEYWORDS43 };44 var STRING = {45 className: 'string',46 contains: [hljs.BACKSLASH_ESCAPE, SUBST],47 variants: [48 {begin: /'/, end: /'/},49 {begin: /"/, end: /"/},50 {begin: /`/, end: /`/},51 {begin: '%[qQwWx]?\\(', end: '\\)'},52 {begin: '%[qQwWx]?\\[', end: '\\]'},53 {begin: '%[qQwWx]?{', end: '}'},54 {begin: '%[qQwWx]?<', end: '>'},55 {begin: '%[qQwWx]?/', end: '/'},56 {begin: '%[qQwWx]?%', end: '%'},57 {begin: '%[qQwWx]?-', end: '-'},58 {begin: '%[qQwWx]?\\|', end: '\\|'},59 {60 // \B in the beginning suppresses recognition of ?-sequences where ?61 // is the last character of a preceding identifier, as in: `func?4`62 begin: /\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/63 }64 ]65 };66 var PARAMS = {67 className: 'params',68 begin: '\\(', end: '\\)',69 keywords: RUBY_KEYWORDS70 };71 var RUBY_DEFAULT_CONTAINS = [72 STRING,73 IRB_OBJECT,74 {75 className: 'class',76 beginKeywords: 'class module', end: '$|;',77 illegal: /=/,78 contains: [79 hljs.inherit(hljs.TITLE_MODE, {begin: '[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?'}),80 {81 className: 'inheritance',82 begin: '<\\s*',83 contains: [{84 className: 'parent',85 begin: '(' + hljs.IDENT_RE + '::)?' + hljs.IDENT_RE86 }]87 }88 ].concat(COMMENT_MODES)89 },90 {91 className: 'function',92 beginKeywords: 'def', end: '$|;',93 contains: [94 hljs.inherit(hljs.TITLE_MODE, {begin: RUBY_METHOD_RE}),95 PARAMS96 ].concat(COMMENT_MODES)97 },98 {99 className: 'constant',100 begin: '(::)?(\\b[A-Z]\\w*(::)?)+',101 relevance: 0102 },103 {104 className: 'symbol',105 begin: hljs.UNDERSCORE_IDENT_RE + '(\\!|\\?)?:',106 relevance: 0107 },108 {109 className: 'symbol',110 begin: ':',111 contains: [STRING, {begin: RUBY_METHOD_RE}],112 relevance: 0113 },114 {115 className: 'number',116 begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',117 relevance: 0118 },119 {120 className: 'variable',121 begin: '(\\$\\W)|((\\$|\\@\\@?)(\\w+))'122 },123 { // regexp container124 begin: '(' + hljs.RE_STARTERS_RE + ')\\s*',125 contains: [126 IRB_OBJECT,127 {128 className: 'regexp',129 contains: [hljs.BACKSLASH_ESCAPE, SUBST],130 illegal: /\n/,131 variants: [132 {begin: '/', end: '/[a-z]*'},133 {begin: '%r{', end: '}[a-z]*'},134 {begin: '%r\\(', end: '\\)[a-z]*'},135 {begin: '%r!', end: '![a-z]*'},136 {begin: '%r\\[', end: '\\][a-z]*'}137 ]138 }139 ].concat(COMMENT_MODES),140 relevance: 0141 }142 ].concat(COMMENT_MODES);143 SUBST.contains = RUBY_DEFAULT_CONTAINS;144 PARAMS.contains = RUBY_DEFAULT_CONTAINS;145 var SIMPLE_PROMPT = "[>?]>";146 var DEFAULT_PROMPT = "[\\w#]+\\(\\w+\\):\\d+:\\d+>";147 var RVM_PROMPT = "(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>";148 var IRB_DEFAULT = [149 {150 begin: /^\s*=>/,151 className: 'status',152 starts: {153 end: '$', contains: RUBY_DEFAULT_CONTAINS154 }155 },156 {157 className: 'prompt',158 begin: '^('+SIMPLE_PROMPT+"|"+DEFAULT_PROMPT+'|'+RVM_PROMPT+')',159 starts: {160 end: '$', contains: RUBY_DEFAULT_CONTAINS161 }162 }163 ];164 return {165 aliases: ['rb', 'gemspec', 'podspec', 'thor', 'irb'],166 keywords: RUBY_KEYWORDS,167 contains: COMMENT_MODES.concat(IRB_DEFAULT).concat(RUBY_DEFAULT_CONTAINS)168 };...
website.tour.event_sale.js
Source:website.tour.event_sale.js
...9},10 [11 {12 content: "Go to the `Events` page",13 trigger: 'a[href*="/event"]:contains("Conference on Business Apps"):first',14 },15 {16 content: "Select 1 unit of `Standard` ticket type",17 extra_trigger: '#wrap:not(:has(a[href*="/event"]:contains("Conference on Business Apps")))',18 trigger: 'select:eq(0)',19 run: 'text 1',20 },21 {22 content: "Select 2 units of `VIP` ticket type",23 extra_trigger: 'select:eq(0):has(option:contains(1):propSelected)',24 trigger: 'select:eq(1)',25 run: 'text 2',26 },27 {28 content: "Click on `Order Now` button",29 extra_trigger: 'select:eq(1):has(option:contains(2):propSelected)',30 trigger: '.btn-primary:contains("Register Now")',31 },32 {33 content: "Fill attendees details",34 trigger: 'form[id="attendee_registration"] .btn:contains("Continue")',35 run: function () {36 $("input[name='1-name']").val("Att1");37 $("input[name='1-phone']").val("111 111");38 $("input[name='1-email']").val("att1@example.com");39 $("input[name='2-name']").val("Att2");40 $("input[name='2-phone']").val("222 222");41 $("input[name='2-email']").val("att2@example.com");42 $("input[name='3-name']").val("Att3");43 $("input[name='3-phone']").val("333 333");44 $("input[name='3-email']").val("att3@example.com");45 },46 },47 {48 content: "Validate attendees details",49 extra_trigger: "input[name='1-name'], input[name='2-name'], input[name='3-name']",50 trigger: 'button:contains("Continue")',51 },52 {53 content: "Check that the cart contains exactly 3 triggers",54 trigger: 'a:has(.my_cart_quantity:containsExact(3))',55 run: function () {}, // it's a check56 },57 {58 content: "go to cart",59 trigger: 'a:contains(Return to Cart)',60 },61 {62 content: "Modify the cart to add 1 unit of `VIP` ticket type",63 extra_trigger: "#cart_products:contains(Standard):contains(VIP)",64 trigger: "#cart_products tr:contains(VIP) .fa-plus",65 },66 {67 content: "Now click on `Process Checkout`",68 extra_trigger: 'a:has(.my_cart_quantity):contains(4)',69 trigger: '.btn-primary:contains("Process Checkout")'70 },71 {72 content: "Complete the checkout",73 trigger: 'a[href="/shop/confirm_order"]:contains("Confirm")',74 },75 {76 content: "Check that the subtotal is 5,500.00 USD", // this test will fail if the currency of the main company is not USD77 trigger: '#order_total_untaxed .oe_currency_value:contains("5,500.00")',78 run: function () {}, // it's a check79 },80 {81 content: "Select `Wire Transfer` payment method",82 trigger: '#payment_method label:contains("Wire Transfer")',83 },84 {85 content: "Pay",86 //Either there are multiple payment methods, and one is checked, either there is only one, and therefore there are no radio inputs87 extra_trigger: '#payment_method label:contains("Wire Transfer") input:checked,#payment_method:not(:has("input:radio:visible"))',88 trigger: 'button[id="o_payment_form_pay"]:visible',89 },90 {91 content: "Last step",92 trigger: '.oe_website_sale:contains("Thank you for your order")',93 timeout: 30000,94 }95 ]96);...
tree.js
Source:tree.js
1module.exports = {2 'tree': function (browser) {3 browser4 .url('http://localhost:8080/examples/tree/')5 .waitForElementVisible('li', 1000)6 .assert.count('.item', 12)7 .assert.count('.add', 4)8 .assert.count('.item > ul', 4)9 .assert.notVisible('#demo li ul')10 .assert.containsText('#demo li div span', '[+]')11 // expand root12 .click('.bold')13 .assert.visible('#demo ul')14 .assert.evaluate(function () {15 return document.querySelector('#demo li ul').children.length === 416 })17 .assert.containsText('#demo li div span', '[-]')18 .assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')19 .assert.containsText('#demo > .item > ul > .item:nth-child(2)', 'wat')20 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', 'child folder')21 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', '[+]')22 // add items to root23 .click('#demo > .item > ul > .add')24 .assert.evaluate(function () {25 return document.querySelector('#demo li ul').children.length === 526 })27 .assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')28 .assert.containsText('#demo > .item > ul > .item:nth-child(2)', 'wat')29 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', 'child folder')30 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', '[+]')31 .assert.containsText('#demo > .item > ul > .item:nth-child(4)', 'new stuff')32 // add another item33 .click('#demo > .item > ul > .add')34 .assert.evaluate(function () {35 return document.querySelector('#demo li ul').children.length === 636 })37 .assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')38 .assert.containsText('#demo > .item > ul > .item:nth-child(2)', 'wat')39 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', 'child folder')40 .assert.containsText('#demo > .item > ul > .item:nth-child(3)', '[+]')41 .assert.containsText('#demo > .item > ul > .item:nth-child(4)', 'new stuff')42 .assert.containsText('#demo > .item > ul > .item:nth-child(5)', 'new stuff')43 .click('#demo ul .bold')44 .assert.visible('#demo ul ul')45 .assert.containsText('#demo ul > .item:nth-child(3)', '[-]')46 .assert.evaluate(function () {47 return document.querySelector('#demo ul ul').children.length === 548 })49 .click('.bold')50 .assert.notVisible('#demo ul')51 .assert.containsText('#demo li div span', '[+]')52 .click('.bold')53 .assert.visible('#demo ul')54 .assert.containsText('#demo li div span', '[-]')55 .dblClick('#demo ul > .item div')56 .assert.count('.item', 15)57 .assert.count('.item > ul', 5)58 .assert.containsText('#demo ul > .item:nth-child(1)', '[-]')59 .assert.evaluate(function () {60 var firstItem = document.querySelector('#demo ul > .item:nth-child(1)')61 var ul = firstItem.querySelector('ul')62 return ul.children.length === 263 })64 .end()65 }...
select2.js
Source:select2.js
1/* globals vm */2module.exports = {3 'select2': function (browser) {4 browser5 .url('http://localhost:8080/examples/select2/')6 .waitForElementVisible('.select2', 1000)7 .assert.elementPresent('select')8 .assert.containsText('p', 'Selected: 0')9 .assert.containsText('span.select2', 'Select one')10 .moveToElement('span.select2', 5, 5).mouseButtonClick()11 .assert.count('.select2-results__option', 3)12 .assert.containsText('.select2-results__option:nth-child(1)', 'Select one')13 .assert.containsText('.select2-results__option:nth-child(2)', 'Hello')14 .assert.containsText('.select2-results__option:nth-child(3)', 'World')15 .assert.attributePresent('.select2-results__option:nth-child(1)', 'aria-disabled')16 .click('.select2-results__option:nth-child(2)')17 .assert.count('.select2-results__option', 0)18 .assert.containsText('p', 'Selected: 1')19 .assert.containsText('span.select2', 'Hello')20 // test dynamic options21 .execute(function () {22 vm.options.push({ id: 3, text: 'Vue' })23 })24 .moveToElement('span.select2', 5, 5).mouseButtonClick()25 .assert.count('.select2-results__option', 4)26 .assert.containsText('.select2-results__option:nth-child(1)', 'Select one')27 .assert.containsText('.select2-results__option:nth-child(2)', 'Hello')28 .assert.containsText('.select2-results__option:nth-child(3)', 'World')29 .assert.containsText('.select2-results__option:nth-child(4)', 'Vue')30 .click('.select2-results__option:nth-child(4)')31 .assert.count('.select2-results__option', 0)32 .assert.containsText('p', 'Selected: 3')33 .assert.containsText('span.select2', 'Vue')34 .execute(function () {35 vm.selected = 236 })37 .assert.containsText('p', 'Selected: 2')38 .assert.containsText('span.select2', 'World')39 .end()40 }...
deDupe.recursive.spec.js
Source:deDupe.recursive.spec.js
1var deDupe = require("../../../lib/algorithms/2-linkedLists/deDupe.recursive.js");2var LinkedList = require("../../../lib/dataStructures/linkedList.js");3describe('When using the recursive deDupe() on a linked list of integers', function () {4 var containsDupes;5 var noDupes;6 beforeEach(function() {7 containsDupes = new LinkedList();8 containsDupes.add(1);9 containsDupes.add(2);10 containsDupes.add(1);11 containsDupes.add(3);12 containsDupes.add(4);13 containsDupes.add(4);14 containsDupes.add(4);15 containsDupes.add(5);16 containsDupes.add(6);17 containsDupes.add(6);18 containsDupes.add(6);19 noDupes = new LinkedList();20 noDupes.add(1);21 noDupes.add(2);22 noDupes.add(3);23 noDupes.add(4);24 noDupes.add(5);25 noDupes.add(6);26 });27 it('any duplicate elements will be removed from the linked list.', function () {28 var result = deDupe(containsDupes.start);29 expect(JSON.stringify(result)).toEqual(JSON.stringify(noDupes.start));30 });31 it('if there are no dups, nothing will happen', function () {32 var result = deDupe(noDupes.start);33 expect(JSON.stringify(result)).toEqual(JSON.stringify(noDupes.start));34 });...
deDupe.spec.js
Source:deDupe.spec.js
1var deDupe = require("../../../lib/algorithms/2-linkedLists/deDupe.js");2var LinkedList = require("../../../lib/dataStructures/linkedList.js");3describe('When using deDupe() on a linked list of integers', function () {4 var containsDupes;5 var noDupes;6 beforeEach(function() {7 containsDupes = new LinkedList();8 containsDupes.add(1);9 containsDupes.add(2);10 containsDupes.add(1);11 containsDupes.add(3);12 containsDupes.add(4);13 containsDupes.add(4);14 containsDupes.add(4);15 containsDupes.add(5);16 containsDupes.add(6);17 containsDupes.add(6);18 containsDupes.add(6);19 noDupes = new LinkedList();20 noDupes.add(1);21 noDupes.add(2);22 noDupes.add(3);23 noDupes.add(4);24 noDupes.add(5);25 noDupes.add(6);26 });27 it('any duplicate elements will be removed from the linked list.', function () {28 var result = deDupe(containsDupes.start);29 expect(JSON.stringify(result)).toEqual(JSON.stringify(noDupes.start));30 });31 it('if there are no dups, nothing will happen', function () {32 var result = deDupe(noDupes.start);33 expect(JSON.stringify(result)).toEqual(JSON.stringify(noDupes.start));34 });...
Using AI Code Generation
1import test from 'ava';2import contains from 'contains';3test('main', t => {4 t.is(contains('foo', 'foo bar'), true);5 t.is(contains('bar', 'foo bar'), true);6 t.is(contains('baz', 'foo bar'), false);7});8import test from 'ava';9import contains from 'contains';10test('main', t => {11 t.is(contains('foo', 'foo bar'), true);12 t.is(contains('bar', 'foo bar'), true);13 t.is(contains('baz', 'foo bar'), false);14});15import test from 'ava';16import contains from 'contains';17test('main', t => {18 t.is(contains('foo', 'foo bar'), true);19 t.is(contains('bar', 'foo bar'), true);20 t.is(contains('baz', 'foo bar'), false);21});22import test from 'ava';23import contains from 'contains';24test('main', t => {25 t.is(contains('foo', 'foo bar'), true);26 t.is(contains('bar', 'foo bar'), true);27 t.is(contains('baz', 'foo bar'), false);28});29import test from 'ava';30import contains from 'contains';31test('main', t => {32 t.is(contains('foo', 'foo bar'), true);33 t.is(contains('bar', 'foo bar'), true);34 t.is(contains('baz', 'foo bar'), false);35});36import test from 'ava';37import contains from 'contains';38test('main', t => {39 t.is(contains('foo', 'foo bar'), true);40 t.is(contains('bar', 'foo bar'), true);41 t.is(contains('baz', 'foo bar'), false);42});43import test from 'ava';44import contains from 'contains';45test('main', t => {46 t.is(contains('foo', 'foo bar'), true);
Using AI Code Generation
1import test from 'ava';2import contains from 'contains';3test('contains', t => {4 t.true(contains('foo', 'foo'));5 t.true(contains('foo', 'foo'));6 t.true(contains('foo', 'foo'));7});8import test from 'ava';9import contains from 'contains';10test('contains', t => {11 t.true(contains('foo', 'foo'));12 t.true(contains('foo', 'foo'));13 t.true(contains('foo', 'foo'));14});15import test from 'ava';16import contains from 'contains';17test('contains', t => {18 t.true(contains('foo', 'foo'));19 t.true(contains('foo', 'foo'));20 t.true(contains('foo', 'foo'));21});22import test from 'ava';23import contains from 'contains';24test('contains', t => {25 t.true(contains('foo', 'foo'));26 t.true(contains('foo', 'foo'));27 t.true(contains('foo', 'foo'));28});29import test from 'ava';30import contains from 'contains';31test('contains', t => {32 t.true(contains('foo', 'foo'));33 t.true(contains('foo', 'foo'));34 t.true(contains('foo', 'foo'));35});36import test from 'ava';37import contains from 'contains';38test('contains', t => {39 t.true(contains('foo', 'foo'));40 t.true(contains('foo', 'foo'));41 t.true(contains('foo', 'foo'));42});43import test from 'ava';44import contains from 'contains';45test('contains', t => {46 t.true(contains('foo', 'foo'));47 t.true(contains('foo', 'foo'));48 t.true(contains('foo', 'foo'));49});50import test from 'ava';51import contains from 'contains';52test('contains', t => {53 t.true(contains('foo', 'foo'));54 t.true(contains('foo', 'foo'));55 t.true(contains('foo', 'foo'));56});57import test from 'ava';58import contains from 'contains';59test('contains', t => {60 t.true(contains('foo',
Using AI Code Generation
1import test from 'ava';2import contains from './contains.js';3test('contains', t => {4 const arr = [1, 2, 3, 4, 5, 6];5 t.true(contains(arr, 3));6 t.false(contains(arr, 7));7});8const contains = (arr, val) => {9 return arr.indexOf(val) !== -1;10}11export default contains;
Using AI Code Generation
1import test from 'ava';2import contains from 'contains';3test('contains', t => {4 t.true(contains('foo', 'foo'));5 t.false(contains('foo', 'bar'));6});7{8 "scripts": {9 },10 "devDependencies": {11 }12}
Using AI Code Generation
1const test = require('ava');2const contains = require('./contains');3test('contains() returns true if the value is in the array', t => {4 const arr = [1,2,3];5 t.true(contains(arr, 1));6});7test('contains() returns false if the value is not in the array', t => {8 const arr = [1,2,3];9 t.false(contains(arr, 4));10});11const _ = require('lodash');12function contains(arr, value) {13 return _.contains(arr, value);14}15module.exports = contains;16const test = require('ava');17test('contains() returns true if the value is in the array', t => {18 const arr = [1,2,3];19 t.true(arr.includes(1));20});21test('contains() returns false if the value is not in the array', t => {22 const arr = [1,2,3];23 t.false(arr.includes(4));24});25const _ = require('lodash');26function contains(arr, value) {27 return _.contains(arr, value);28}29module.exports = contains;30const test = require('ava');31test('contains() returns true if the value is in the array', t => {32 const arr = [1,2,3];33 t.true(arr.indexOf(1) > -1);34});35test('contains() returns false if the value is not in the array', t => {36 const arr = [1,2,3];37 t.false(arr.indexOf(4) > -1);38});39const _ = require('lodash');40function contains(arr, value) {41 return _.contains(arr, value);42}43module.exports = contains;
Using AI Code Generation
1import test from 'ava';2import contains from './contains';3test('contains', t => {4 const result = contains('abc', 'b');5 t.is(result, true);6});7export default function contains(str, value) {8 return str.indexOf(value) !== -1;9}10export default function contains(str, value) {11 return str.indexOf(value) !== -1;12}13export default function contains(str, value) {14 return str.indexOf(value) !== -1;15}16export default function contains(str, value) {17 return str.indexOf(value) !== -1;18}19export default function contains(str, value) {20 return str.indexOf(value) !== -1;21}22export default function contains(str, value) {23 return str.indexOf(value) !== -1;24}25export default function contains(str, value) {26 return str.indexOf(value) !== -1;27}28export default function contains(str, value) {29 return str.indexOf(value) !== -1;30}31export default function contains(str, value) {32 return str.indexOf(value) !== -1;33}34export default function contains(str, value) {35 return str.indexOf(value) !== -1;36}37export default function contains(str, value) {38 return str.indexOf(value) !== -1;39}40export default function contains(str, value) {41 return str.indexOf(value) !== -1;42}43export default function contains(str, value) {44 return str.indexOf(value) !== -1;45}
Using AI Code Generation
1var str = "Hello world, welcome to the universe.";2var n = str.includes("world");3console.log(n);4var fruits = ["Banana", "Orange", "Apple", "Mango"];5var n = fruits.includes("Apple");6console.log(n);7var fruits = ["Banana", "Orange", "Apple", "Mango"];8var n = fruits.includes("Banana", 1);9console.log(n);10var fruits = ["Banana", "Orange", "Apple", "Mango"];11var n = fruits.includes("Banana", 2);12console.log(n);13var fruits = ["Banana", "Orange", "Apple", "Mango"];14var n = fruits.includes("Mango", 2);15console.log(n);16var fruits = ["Banana", "Orange", "Apple", "Mango"];17var n = fruits.includes("Mango", 3);18console.log(n);19var fruits = ["Banana", "Orange", "Apple", "Mango"];20var n = fruits.includes("Mango", 4);21console.log(n);22var fruits = ["Banana", "Orange", "Apple", "Mango"];23var n = fruits.includes("Mango", 5);24console.log(n);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!