Best JavaScript code snippet using wpt
contacts-select.https.window.js
Source:contacts-select.https.window.js
1// META: script=/resources/test-only-api.js2// META: script=/resources/testdriver.js3// META: script=/resources/testdriver-vendor.js4// META: script=resources/helpers.js5'use strict';6// Verifies that |func|, when invoked, throws a TypeError exception.7async function expectTypeError(func) {8 try {9 await func();10 } catch (e) {11 assert_equals(e.name, 'TypeError');12 return;13 }14 assert_unreached('expected a TypeError, but none was thrown');15}16promise_test(async () => {17 try {18 await navigator.contacts.select(['name']);19 assert_unreached('expected a SecurityError, but none was thrown');20 } catch (e) {21 assert_equals(e.name, 'SecurityError');22 }23}, 'The Contact API requires a user gesture')24contactsTestWithUserActivation(async (test, setSelectedContacts) => {25 // At least one property must be provided.26 await expectTypeError(() => navigator.contacts.select());27 await expectTypeError(() => navigator.contacts.select([]));28 // Per WebIDL parsing, no invalid values may be provided.29 await expectTypeError(() =>30 navigator.contacts.select(['']));31 await expectTypeError(() =>32 navigator.contacts.select(['foo']));33 await expectTypeError(() =>34 navigator.contacts.select(['name', 'photo']));35}, 'The Contact API requires valid properties to be provided');36contactsTestWithUserActivation(async (test, setSelectedContacts) => {37 // Returns a NULL result, indicating that no results are available.38 setSelectedContacts(null);39 await expectTypeError(() => navigator.contacts.select(['name']));40}, 'The Contact API can fail when the selector cannot be opened');41contactsTestWithUserActivation(async (test, setSelectedContacts) => {42 setSelectedContacts([]);43 const properties = await navigator.contacts.getProperties();44 assert_true(properties.length > 0);45 // Requesting the available properties should not fail.46 await navigator.contacts.select(properties);47}, 'Supported contact properties are exposed.');48contactsTestWithUserActivation(async (test, setSelectedContacts) => {49 const dwightAddress = {50 country: 'US',51 city: 'Scranton',52 addressLine: ['Schrute Farms'],53 };54 const michaelIcons = [new Blob('image binary data'.split(''), {type: 'image/test'})];55 // Returns two contacts with all information available.56 setSelectedContacts([57 { name: ['Dwight Schrute'], email: ['dwight@schrutefarmsbnb.com'], tel: ['000-0000'], address: [dwightAddress] },58 { name: ['Michael Scott', 'Prison Mike'], email: ['michael@dundermifflin.com'], icon: michaelIcons },59 ]);60 let results = await navigator.contacts.select(['name', 'email', 'icon', 'tel', 'address'], { multiple: true });61 assert_equals(results.length, 2);62 results = results.sort((c1, c2) => JSON.stringify(c1) < JSON.stringify(c2) ? -1 : 1);63 {64 const michael = results[0];65 assert_own_property(michael, 'name');66 assert_own_property(michael, 'email');67 assert_own_property(michael, 'tel');68 assert_own_property(michael, 'address');69 assert_own_property(michael, 'icon');70 assert_array_equals(michael.name, ['Michael Scott', 'Prison Mike']);71 assert_array_equals(michael.email, ['michael@dundermifflin.com']);72 assert_array_equals(michael.tel, []);73 assert_array_equals(michael.address, []);74 assert_equals(michael.icon.length, michaelIcons.length);75 assert_equals(michael.icon[0].type, michaelIcons[0].type);76 assert_equals(michael.icon[0].size, michaelIcons[0].size);77 assert_equals(await michael.icon[0].text(), await michaelIcons[0].text());78 }79 {80 const dwight = results[1];81 assert_own_property(dwight, 'name');82 assert_own_property(dwight, 'email');83 assert_own_property(dwight, 'tel');84 assert_own_property(dwight, 'address');85 assert_own_property(dwight, 'icon');86 assert_array_equals(dwight.name, ['Dwight Schrute']);87 assert_array_equals(dwight.email, ['dwight@schrutefarmsbnb.com']);88 assert_array_equals(dwight.tel, ['000-0000']);89 assert_array_equals(dwight.icon, []);90 assert_equals(dwight.address.length, 1);91 const selectedAddress = dwight.address[0];92 assert_object_equals({93 country: selectedAddress.country,94 city: selectedAddress.city,95 addressLine: selectedAddress.addressLine,96 }, dwightAddress);97 }98}, 'The Contact API correctly returns ContactInfo entries');99contactsTestWithUserActivation(async (test, setSelectedContacts) => {100 // Returns two contacts with all information available.101 setSelectedContacts([102 { name: ['Dwight Schrute'], email: ['dwight@schrutefarmsbnb.com'], tel: ['000-0000'] },103 { name: ['Michael Scott', 'Prison Mike'], email: ['michael@dundermifflin.com'] },104 ]);105 const results = await navigator.contacts.select(['name', 'email', 'tel']);106 assert_equals(results.length, 1);107}, 'Only one contact is returned if `multiple` is not set.');108contactsTestWithUserActivation(async (test, setSelectedContacts) => {109 // Returns partial information since no e-mail addresses are requested.110 setSelectedContacts([{ name: ['Creed'], email: ['creedthoughts@www.creedthoughts.gov.www'] }]);111 const results = await navigator.contacts.select(['name']);112 assert_equals(results.length, 1);113 {114 const creed = results[0];115 assert_array_equals(creed.name, ['Creed']);116 assert_equals(creed.email, undefined);117 assert_equals(creed.tel, undefined);118 }119}, 'The Contact API does not include fields that were not requested');120contactsTestWithUserActivation(async (test, setSelectedContacts) => {121 // Returns partial information since no e-mail addresses are requested.122 setSelectedContacts([{ name: ['Kelly'] }]);123 // First request should work.124 const promise1 = new Promise((resolve, reject) => {125 navigator.contacts.select(['name']).then(resolve)126 .catch(e => reject(e.message));127 });128 // Second request should fail (since the first one didn't complete yet).129 const promise2 = new Promise((resolve, reject) => {130 navigator.contacts.select(['name']).then(contacts => reject('This was supposed to fail'))131 .catch(e => resolve(e.name));132 });133 const results = await Promise.all([promise1, promise2]);134 const contacts = results[0];135 assert_equals(contacts.length, 1);136 const contact = contacts[0];137 assert_equals(contact.name[0], 'Kelly');138 assert_equals(results[1], 'InvalidStateError');139}, 'The Contact API cannot be used again until the first operation is complete.');140contactsTestWithUserActivation(async (test, setSelectedContacts) => {141 const iframe = document.createElement('iframe');142 document.body.appendChild(iframe);143 iframe.src = 'resources/non-main-frame-select.html';144 await new Promise(resolve => window.addEventListener('message', event => resolve(event.data)))145 .then(data => assert_equals(data.errorMsg, 'InvalidStateError'))146 .finally(() => iframe.remove())...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.michaelIcons();3var wptoolkit = require('wptoolkit');4wptoolkit.michaelIcons();5var wptoolkit = require('wptoolkit');6wptoolkit.michaelIcons();7var wptoolkit = require('wptoolkit');8wptoolkit.michaelIcons();9var wptoolkit = require('wptoolkit');10wptoolkit.michaelIcons();11var wptoolkit = require('wptoolkit');12wptoolkit.michaelIcons();13var wptoolkit = require('wptoolkit');14wptoolkit.michaelIcons();15var wptoolkit = require('wptoolkit');16wptoolkit.michaelIcons();17var wptoolkit = require('wptoolkit');18wptoolkit.michaelIcons();19var wptoolkit = require('wptoolkit');20wptoolkit.michaelIcons();21var wptoolkit = require('wptoolkit');22wptoolkit.michaelIcons();23var wptoolkit = require('wptoolkit');24wptoolkit.michaelIcons();25var wptoolkit = require('wptoolkit');
Using AI Code Generation
1var wptools = require('wptools');2wptools.michaelIcons('Barack Obama', function(err, resp){3 if(err){4 console.log(err);5 }else{6 console.log(resp);7 }8});9var wptools = require('wptools');10wptools.michaelIcons('Barack Obama', function(err, resp){11 if(err){12 console.log(err);13 }else{14 console.log(resp);15 }16});17var wptools = require('wptools');18wptools.michaelIcons('Barack Obama', function(err, resp){19 if(err){20 console.log(err);21 }else{22 console.log(resp);23 }24});25var wptools = require('wptools');26wptools.michaelIcons('Barack Obama', function(err, resp){27 if(err){28 console.log(err);29 }else{30 console.log(resp);31 }32});33var wptools = require('wptools');34wptools.michaelIcons('Barack Obama', function(err, resp){35 if(err){36 console.log(err);37 }else{38 console.log(resp);39 }40});41var wptools = require('wptools');42wptools.michaelIcons('Barack Obama', function(err, resp){43 if(err){
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3wptools.michaelIcons('Michael Jackson', function(err, res) {4 if (err) {5 console.log(err);6 } else {7 console.log(res);8 }9});10- [wptools](
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Michael Jackson');3page.michaelIcons(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Michael Jackson');8page.michaelImages(function(err, resp) {9 console.log(resp);10});
Using AI Code Generation
1var wptools = require('wptools');2var icon = wptools.michaelIcons('Michael Jackson', 'json');3console.log(icon);4var wptools = require('wptools');5var icon = wptools.michaelIcons('Michael Jackson', 'json');6console.log(icon);7var wptools = require('wptools');8var icon = wptools.michaelIcons('Michael Jackson', 'json');9console.log(icon);10var wptools = require('wptools');11var icon = wptools.michaelIcons('Michael Jackson', 'json');12console.log(icon);13var wptools = require('wptools');14var icon = wptools.michaelIcons('Michael Jackson', 'json');15console.log(icon);16var wptools = require('wptools');17var icon = wptools.michaelIcons('Michael Jackson', 'json');18console.log(icon);19var wptools = require('wptools');20var icon = wptools.michaelIcons('Michael Jackson', 'json');21console.log(icon);22var wptools = require('wptools');23var icon = wptools.michaelIcons('Michael Jackson', 'json');24console.log(icon);25var wptools = require('wptools');26var icon = wptools.michaelIcons('Michael Jackson', 'json');27console.log(icon);28var wptools = require('wptools');29var icon = wptools.michaelIcons('Michael Jackson', 'json');30console.log(icon);31var wptools = require('
Using AI Code Generation
1const wptools = require('wptools');2const wiki = wptools.page('michael jackson');3wiki.michaelIcons().then(function(result) {4 console.log(result);5});6const wptools = require('wptools');7const wiki = wptools.page('michael jackson');8wiki.michaelIcons().then(function(result) {9 console.log(result);10});11const wptools = require('wptools');12const wiki = wptools.page('michael jackson');13wiki.michaelIcons().then(function(result) {14 console.log(result);15});16const wptools = require('wptools');17const wiki = wptools.page('michael jackson');18wiki.michaelIcons().then(function(result) {19 console.log(result);20});21const wptools = require('wptools');22const wiki = wptools.page('michael jackson');23wiki.michaelIcons().then(function(result) {24 console.log(result);25});26const wptools = require('wptools');27const wiki = wptools.page('michael jackson');28wiki.michaelIcons().then(function(result) {29 console.log(result);30});
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');3console.log(icon);4var wptoolkit = require('wptoolkit');5var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');6console.log(icon);7var wptoolkit = require('wptoolkit');8var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');9console.log(icon);10var wptoolkit = require('wptoolkit');11var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');12console.log(icon);13var wptoolkit = require('wptoolkit');14var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');15console.log(icon);16var wptoolkit = require('wptoolkit');17var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');18console.log(icon);19var wptoolkit = require('wptoolkit');20var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');21console.log(icon);22var wptoolkit = require('wptoolkit');23var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');24console.log(icon);25var wptoolkit = require('wptoolkit');26var icon = wptoolkit.michaelIcons('icon-uniF017', 20, 'red');27console.log(icon);28var wptoolkit = require('wptoolkit');
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!!