How to use isEventSupported method in Playwright Internal

Best JavaScript code snippet using playwright-internal

flex.test.js

Source:flex.test.js Github

copy

Full Screen

1const executor = require('../../lib/flex')2const Helper = require('../../__fixtures__/unit/helper')3const { Action } = require('../../lib/actions/action')4describe('Test beforeValidate and afterValidate invocations', async () => {5 let context6 let registry = { validators: new Map(), actions: new Map() }7 let action8 let config = `9 version: 210 hydrabot:11 - when: pull_request.*12 validate:13 - do: title14 must_exclude:15 regex: wip|work in progress|do not merge16 message: 'a custom message'17 - do: label18 must_exclude:19 regex: wip|work in progress20 `21 let configWithMultiple = config + `22 - when: pull_request_review.submitted23 validate:24 - do: milestone25 no_empty:26 enabled: true27 `28 beforeEach(() => {29 context = Helper.mockContext()30 Helper.mockConfigWithContext(context, config)31 action = new Action()32 action.beforeValidate = jest.fn()33 action.afterValidate = jest.fn()34 action.supportedEvents = ['pull_request.opened', 'pull_request.edited', 'pull_request_review.submitted']35 registry.actions.set('checks', action)36 })37 test('when event is in configuration', async () => {38 context.event = 'pull_request'39 context.payload.action = 'opened'40 await executor(context, registry)41 expect(action.beforeValidate.mock.calls.length).toBe(1)42 expect(action.afterValidate.mock.calls.length).toBe(1)43 })44 test('when event is not in configuration', async () => {45 context.event = 'pull_request_review'46 context.payload.action = 'submitted'47 await executor(context, registry)48 expect(action.beforeValidate.mock.calls.length).toBe(0)49 expect(action.afterValidate.mock.calls.length).toBe(0)50 })51 test('when event is in configuration with multiple whens', async () => {52 Helper.mockConfigWithContext(context, configWithMultiple)53 context.event = 'pull_request_review'54 context.payload.action = 'submitted'55 await executor(context, registry)56 expect(action.beforeValidate.mock.calls.length).toBe(1)57 expect(action.afterValidate.mock.calls.length).toBe(1)58 })59 test('when event is NOT in configuration with multiple whens', async () => {60 Helper.mockConfigWithContext(context, configWithMultiple)61 context.event = 'pull_request_review'62 context.payload.action = 'commented'63 await executor(context, registry)64 expect(action.beforeValidate.mock.calls.length).toBe(0)65 expect(action.afterValidate.mock.calls.length).toBe(0)66 })67})68describe('#executor', () => {69 test('Bad YML', async () => {70 let context = Helper.mockContext()71 context.event = 'pull_request'72 context.payload.action = 'opened'73 Helper.mockConfigWithContext(context, `74 version: 275 hydrabot:76 when: pull_request.*77 `,78 {files: ['.github/hydrabot.yml']}79 )80 context.event = 'pull_request'81 context.payload.action = 'opened'82 context.github.checks.create = jest.fn()83 context.github.checks.update = jest.fn()84 await executor(context, { validators: new Map(), actions: new Map() })85 expect(context.github.checks.update.mock.calls.length).toBe(0)86 expect(context.github.checks.create.mock.calls.length).toBe(1)87 const theCall = context.github.checks.create.mock.calls[0][0]88 expect(theCall.status).toBe('completed')89 expect(theCall.conclusion).toBe('cancelled')90 })91 test('One When', async () => {92 let context = Helper.mockContext('title')93 Helper.mockConfigWithContext(context, `94 version: 295 hydrabot:96 - when: pull_request.*97 validate:98 - do: title99 must_include:100 regex: wip|work in progress|do not merge101 message: 'a custom message'102 - do: label103 must_include:104 regex: wip|work in progress105 pass:106 - do: checks107 status: success108 payload:109 title: Success!!110 summary: You are ready to merge111 fail:112 - do: checks113 status: success114 payload:115 title: Success!!116 summary: You are ready to merge117 `)118 let registry = { validators: new Map(), actions: new Map() }119 context.event = 'pull_request'120 context.payload.action = 'opened'121 await executor(context, registry)122 // test that the registry will register dynamicly.123 expect(registry.validators.get('title')).toBeDefined()124 expect(registry.validators.get('label')).toBeDefined()125 let title = {126 validate: jest.fn().mockReturnValue({status: 'pass'}),127 isEventSupported: jest.fn().mockReturnValue(true)128 }129 let label = {130 validate: jest.fn().mockReturnValue({status: 'pass'}),131 isEventSupported: jest.fn().mockReturnValue(true)132 }133 registry.validators.set('title', title)134 registry.validators.set('label', label)135 let checks = {136 beforeValidate: jest.fn(),137 afterValidate: jest.fn(),138 isEventSupported: jest.fn().mockReturnValue(false)139 }140 registry.actions.set('checks', checks)141 await executor(context, registry)142 expect(title.validate).toHaveBeenCalledTimes(1)143 expect(label.validate).toHaveBeenCalledTimes(1)144 expect(checks.beforeValidate).toHaveBeenCalledTimes(0)145 expect(checks.afterValidate).toHaveBeenCalledTimes(0)146 })147 test('Comma seperated events', async () => {148 let context = Helper.mockContext('title')149 Helper.mockConfigWithContext(context, `150 version: 2151 hydrabot:152 - when: pull_request.opened, issues.opened153 validate:154 - do: title155 must_include:156 regex: wip|work in progress|do not merge157 - do: issueOnly158 pass:159 - do: checks160 status: success161 payload:162 title: Success!!163 summary: You are ready to merge164 fail:165 - do: checks166 status: success167 payload:168 title: Success!!169 summary: You are ready to merge170 `)171 let registry = { validators: new Map(), actions: new Map() }172 let title = {173 validate: jest.fn(value => Promise.resolve({status: 'pass'})),174 isEventSupported: jest.fn().mockReturnValue(true)175 }176 registry.validators.set('title', title)177 let issueOnly = {178 validate: jest.fn(value => Promise.resolve({status: 'pass'})),179 isEventSupported: jest.fn(event => { return (event === 'issues.opened') })180 }181 registry.validators.set('issueOnly', issueOnly)182 let checks = {183 beforeValidate: jest.fn(),184 afterValidate: jest.fn(),185 isEventSupported: jest.fn(event => { return (event === 'pull_request.opened') })186 }187 registry.actions.set('checks', checks)188 context.event = 'pull_request'189 context.payload.action = 'opened'190 await executor(context, registry)191 expect(title.validate).toHaveBeenCalledTimes(1)192 expect(title.isEventSupported).toHaveBeenCalledTimes(1)193 expect(issueOnly.validate).toHaveBeenCalledTimes(0)194 expect(issueOnly.isEventSupported).toHaveBeenCalledTimes(1)195 expect(checks.beforeValidate).toHaveBeenCalledTimes(1)196 expect(checks.afterValidate).toHaveBeenCalledTimes(1)197 context.event = 'issues'198 context.payload.action = 'opened'199 await executor(context, registry)200 expect(title.validate).toHaveBeenCalledTimes(2)201 expect(title.isEventSupported).toHaveBeenCalledTimes(2)202 expect(issueOnly.validate).toHaveBeenCalledTimes(1)203 expect(issueOnly.isEventSupported).toHaveBeenCalledTimes(2)204 expect(checks.beforeValidate).toHaveBeenCalledTimes(1)205 expect(checks.afterValidate).toHaveBeenCalledTimes(1)206 })207 test('Multiple Whens', async () => {208 let context = Helper.mockContext('title')209 Helper.mockConfigWithContext(context, `210 version: 2211 hydrabot:212 - when: pull_request.opened213 validate:214 - do: title215 must_exclude:216 regex: 'wip'217 pass:218 - do: checks219 status: success220 payload:221 title: Success!!222 summary: You are ready to merge223 fail:224 - do: checks225 status: success226 payload:227 title: Success!!228 summary: You are ready to merge229 - when: issues.opened230 validate:231 - do: label232 must_exclude:233 regex: 'wip'234 - do: title235 pass:236 - do: checks237 status: success238 payload:239 title: Success!!240 summary: You are ready to merge241 fail:242 - do: checks243 status: success244 payload:245 title: Success!!246 summary: You are ready to merge247 `)248 let registry = { validators: new Map(), actions: new Map() }249 let title = {250 validate: jest.fn(value => Promise.resolve({status: 'pass'})),251 isEventSupported: jest.fn().mockReturnValue(true)252 }253 registry.validators.set('title', title)254 let label = {255 validate: jest.fn(value => Promise.resolve({status: 'pass'})),256 isEventSupported: jest.fn().mockReturnValue(true)257 }258 registry.validators.set('label', label)259 let checks = {260 beforeValidate: jest.fn(),261 afterValidate: jest.fn(),262 isEventSupported: jest.fn().mockReturnValue(true)263 }264 registry.actions.set('checks', checks)265 context.event = 'pull_request'266 context.payload.action = 'opened'267 await executor(context, registry)268 expect(title.validate).toHaveBeenCalledTimes(1)269 expect(label.validate).toHaveBeenCalledTimes(0)270 expect(checks.beforeValidate).toHaveBeenCalledTimes(1)271 expect(checks.afterValidate).toHaveBeenCalledTimes(1)272 context.event = 'issues'273 await executor(context, registry)274 expect(title.validate).toHaveBeenCalledTimes(2)275 expect(label.validate).toHaveBeenCalledTimes(1)276 expect(checks.beforeValidate).toHaveBeenCalledTimes(2)277 expect(checks.afterValidate).toHaveBeenCalledTimes(2)278 })279 test('isEventInContext is working only for correct event', async () => {280 let context = Helper.mockContext('title')281 Helper.mockConfigWithContext(context, `282 version: 2283 hydrabot:284 - when: pull_request.opened285 validate:286 - do: title287 must_exclude:288 regex: 'wip'289 pass:290 - do: checks291 status: success292 payload:293 title: Success!!294 summary: You are ready to merge295 fail:296 - do: checks297 status: success298 payload:299 title: Success!!300 summary: You are ready to merge301 - when: issues.opened302 validate:303 - do: label304 must_exclude:305 regex: 'wip'306 - do: title307 pass:308 - do: checks309 status: success310 payload:311 title: Success!!312 summary: You are ready to merge313 fail:314 - do: checks315 status: success316 payload:317 title: Success!!318 summary: You are ready to merge319 `)320 let registry = { validators: new Map(), actions: new Map() }321 let title = {322 validate: jest.fn(value => Promise.resolve({status: 'pass'})),323 isEventSupported: jest.fn().mockReturnValue(true)324 }325 registry.validators.set('title', title)326 let label = {327 validate: jest.fn(value => Promise.resolve({status: 'pass'})),328 isEventSupported: jest.fn().mockReturnValue(true)329 }330 registry.validators.set('label', label)331 let checks = {332 beforeValidate: jest.fn(),333 afterValidate: jest.fn(),334 isEventSupported: jest.fn().mockReturnValue(true)335 }336 registry.actions.set('checks', checks)337 context.event = 'pull_request_review'338 context.payload.action = 'opened'339 await executor(context, registry)340 expect(title.validate).toHaveBeenCalledTimes(0)341 expect(label.validate).toHaveBeenCalledTimes(0)342 expect(checks.beforeValidate).toHaveBeenCalledTimes(0)343 expect(checks.afterValidate).toHaveBeenCalledTimes(0)344 context.event = 'pull_request'345 await executor(context, registry)346 expect(title.validate).toHaveBeenCalledTimes(1)347 expect(label.validate).toHaveBeenCalledTimes(0)348 expect(checks.beforeValidate).toHaveBeenCalledTimes(1)349 expect(checks.afterValidate).toHaveBeenCalledTimes(1)350 })351 test('Error handling', async() => {352 let registry = { validators: new Map(), actions: new Map() }353 let errorValidator = {354 validate: jest.fn(value => Promise.reject(new Error('Uncaught error'))),355 isEventSupported: jest.fn().mockReturnValue(true)356 }357 let passAction = {358 beforeValidate: jest.fn(),359 afterValidate: jest.fn(),360 isEventSupported: jest.fn().mockReturnValue(true)361 }362 let errorAction = {363 beforeValidate: jest.fn(),364 afterValidate: jest.fn(),365 isEventSupported: jest.fn().mockReturnValue(true)366 }367 registry.validators.set('error', errorValidator)368 registry.actions.set('pass_action', passAction)369 registry.actions.set('error_action', errorAction)370 let context = Helper.mockContext('error')371 Helper.mockConfigWithContext(context, `372 version: 2373 hydrabot:374 - when: pull_request.opened375 validate:376 - do: error377 pass:378 - do: pass_action379 error:380 - do: error_action381 `)382 context.event = 'pull_request'383 context.payload.action = 'opened'384 await executor(context, registry)385 expect(errorAction.beforeValidate).toHaveBeenCalledTimes(1)386 expect(errorAction.afterValidate).toHaveBeenCalledTimes(1)387 expect(passAction.beforeValidate).toHaveBeenCalledTimes(1)388 expect(passAction.afterValidate).toHaveBeenCalledTimes(0)389 })...

Full Screen

Full Screen

normalizeWheel.js

Source:normalizeWheel.js Github

copy

Full Screen

...12 *13 * Note that `isEventSupported` can give false positives when passed augmented host objects, e.g.:14 * 15 * someElement.onfoo = function(){ };16 * isEventSupported('foo', someElement); // true (even if "foo" is not supported)17 *18 * Also note that in Gecko clients (those that utilize `setAttribute` -based detection) -19 *20 * `isEventSupported('foo', someElement)`;21 *22 * - might create `someElement.foo` property (if "foo" event is supported) which apparently can not be deleted23 * `isEventSupported` sets such property to `undefined` value, but can not fully remove it24 *25 */26var isEventSupported = (function(undef) {27 28 var TAGNAMES = {29 'select':'input','change':'input',30 'submit':'form','reset':'form',31 'error':'img','load':'img','abort':'img'32 };33 34 function isEventSupported(eventName, element) {35 element = element || document.createElement(TAGNAMES[eventName] || 'div');36 eventName = 'on' + eventName;37 38 var isSupported = (eventName in element);39 40 if (!isSupported) {41 // if it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element42 if (!element.setAttribute) {43 element = document.createElement('div');44 }45 if (element.setAttribute && element.removeAttribute) {46 element.setAttribute(eventName, '');47 isSupported = typeof element[eventName] == 'function';48 // if property was created, "remove it" (by setting value to `undefined`)49 if (typeof element[eventName] != 'undefined') {50 element[eventName] = undef;51 }52 element.removeAttribute(eventName);53 }54 }55 56 element = null;57 return isSupported;58 }59 return isEventSupported;60})();61var isEventSupportedWithCache = (function(undef) {62 63 var TAGNAMES = {64 'select':'input','change':'input',65 'submit':'form','reset':'form',66 'error':'img','load':'img','abort':'img'67 }, 68 cache = { };69 70 function isEventSupported(eventName, element) {71 var canCache = (arguments.length == 1);72 73 // only return cached result when no element is given74 if (canCache && cache[eventName]) {75 return cache[eventName];76 }77 78 element = element || document.createElement(TAGNAMES[eventName] || 'div');79 eventName = 'on' + eventName;80 81 // When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize", whereas `in` "catches" those82 var isSupported = (eventName in element);83 84 if (!isSupported) {85 // if it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element86 if (!element.setAttribute) {87 element = document.createElement('div');88 }89 if (element.setAttribute && element.removeAttribute) {90 element.setAttribute(eventName, '');91 isSupported = typeof element[eventName] == 'function';92 // if property was created, "remove it" (by setting value to `undefined`)93 if (typeof element[eventName] != 'undefined') {94 element[eventName] = undef;95 }96 element.removeAttribute(eventName);97 }98 }99 100 element = null;101 return canCache ? (cache[eventName] = isSupported) : isSupported;102 }103 return isEventSupported;104})();105/**106 * Copyright (c) 2015, Facebook, Inc.107 * All rights reserved.108 *109 * This source code is licensed under the BSD-style license found in the110 * LICENSE file in the root directory of this source tree. An additional grant111 * of patent rights can be found in the PATENTS file in the same directory.112 *113 * @providesModule normalizeWheel114 * @typechecks115 */116'use strict';117//var UserAgent_DEPRECATED = require('UserAgent_DEPRECATED');118//var isEventSupported = require('isEventSupported');119// Reasonable defaults120var PIXEL_STEP = 10;121var LINE_HEIGHT = 40;122var PAGE_HEIGHT = 800;123/**124 * Mouse wheel (and 2-finger trackpad) support on the web sucks. It is125 * complicated, thus this doc is long and (hopefully) detailed enough to answer126 * your questions.127 *128 * If you need to react to the mouse wheel in a predictable way, this code is129 * like your bestest friend. * hugs *130 *131 * As of today, there are 4 DOM event types you can listen to:132 *133 * 'wheel' -- Chrome(31+), FF(17+), IE(9+)134 * 'mousewheel' -- Chrome, IE(6+), Opera, Safari135 * 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!136 * 'DOMMouseScroll' -- FF(0.9.7+) since 2003137 *138 * So what to do? The is the best:139 *140 * normalizeWheel.getEventType();141 *142 * In your event callback, use this code to get sane interpretation of the143 * deltas. This code will return an object with properties:144 *145 * spinX -- normalized spin speed (use for zoom) - x plane146 * spinY -- " - y plane147 * pixelX -- normalized distance (to pixels) - x plane148 * pixelY -- " - y plane149 *150 * Wheel values are provided by the browser assuming you are using the wheel to151 * scroll a web page by a number of lines or pixels (or pages). Values can vary152 * significantly on different platforms and browsers, forgetting that you can153 * scroll at different speeds. Some devices (like trackpads) emit more events154 * at smaller increments with fine granularity, and some emit massive jumps with155 * linear speed or acceleration.156 *157 * This code does its best to normalize the deltas for you:158 *159 * - spin is trying to normalize how far the wheel was spun (or trackpad160 * dragged). This is super useful for zoom support where you want to161 * throw away the chunky scroll steps on the PC and make those equal to162 * the slow and smooth tiny steps on the Mac. Key data: This code tries to163 * resolve a single slow step on a wheel to 1.164 *165 * - pixel is normalizing the desired scroll delta in pixel units. You'll166 * get the crazy differences between browsers, but at least it'll be in167 * pixels!168 *169 * - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This170 * should translate to positive value zooming IN, negative zooming OUT.171 * This matches the newer 'wheel' event.172 *173 * Why are there spinX, spinY (or pixels)?174 *175 * - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn176 * with a mouse. It results in side-scrolling in the browser by default.177 *178 * - spinY is what you expect -- it's the classic axis of a mouse wheel.179 *180 * - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and181 * probably is by browsers in conjunction with fancy 3D controllers .. but182 * you know.183 *184 * Implementation info:185 *186 * Examples of 'wheel' event if you scroll slowly (down) by one step with an187 * average mouse:188 *189 * OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)190 * OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)191 * OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)192 * Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)193 * Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)194 *195 * On the trackpad:196 *197 * OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)198 * OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)199 *200 * On other/older browsers.. it's more complicated as there can be multiple and201 * also missing delta values.202 *203 * The 'wheel' event is more standard:204 *205 * http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents206 *207 * The basics is that it includes a unit, deltaMode (pixels, lines, pages), and208 * deltaX, deltaY and deltaZ. Some browsers provide other values to maintain209 * backward compatibility with older events. Those other values help us210 * better normalize spin speed. Example of what the browsers provide:211 *212 * | event.wheelDelta | event.detail213 * ------------------+------------------+--------------214 * Safari v5/OS X | -120 | 0215 * Safari v5/Win7 | -120 | 0216 * Chrome v17/OS X | -120 | 0217 * Chrome v17/Win7 | -120 | 0218 * IE9/Win7 | -120 | undefined219 * Firefox v4/OS X | undefined | 1220 * Firefox v4/Win7 | undefined | 3221 *222 */223function normalizeWheel(/*object*/ event) /*object*/ {224 var sX = 0, sY = 0, // spinX, spinY225 pX = 0, pY = 0; // pixelX, pixelY226 // Legacy227 if ('detail' in event) { sY = event.detail; }228 if ('wheelDelta' in event) { sY = -event.wheelDelta / 120; }229 if ('wheelDeltaY' in event) { sY = -event.wheelDeltaY / 120; }230 if ('wheelDeltaX' in event) { sX = -event.wheelDeltaX / 120; }231 // side scrolling on FF with DOMMouseScroll232 if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {233 sX = sY;234 sY = 0;235 }236 pX = sX * PIXEL_STEP;237 pY = sY * PIXEL_STEP;238 if ('deltaY' in event) { pY = event.deltaY; }239 if ('deltaX' in event) { pX = event.deltaX; }240 if ((pX || pY) && event.deltaMode) {241 if (event.deltaMode == 1) { // delta in LINE units242 pX *= LINE_HEIGHT;243 pY *= LINE_HEIGHT;244 } else { // delta in PAGE units245 pX *= PAGE_HEIGHT;246 pY *= PAGE_HEIGHT;247 }248 }249 // Fall-back if spin cannot be determined250 if (pX && !sX) { sX = (pX < 1) ? -1 : 1; }251 if (pY && !sY) { sY = (pY < 1) ? -1 : 1; }252 return { spinX : sX,253 spinY : sY,254 pixelX : pX,255 pixelY : pY };256}257/**258 * The best combination if you prefer spinX + spinY normalization. It favors259 * the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with260 * 'wheel' event, making spin speed determination impossible.261 */262normalizeWheel.getEventType = function() /*string*/ {263 return (isFirefox())264 ? 'DOMMouseScroll'265 : (isEventSupported('wheel'))266 ? 'wheel'267 : 'mousewheel';...

Full Screen

Full Screen

isEventSupported.js

Source:isEventSupported.js Github

copy

Full Screen

...13 done();14 });15 });16 it('allows you to pass an element to test against', function() {17 expect(isEventSupported('click'), document.createElement('a')).to.be(true);18 });19 it('allows you to pass an string name for an element to test against', function() {20 expect(isEventSupported('click', 'a')).to.be(true);21 });22 it('allows you to pass something other then a DOM element or string', function() {23 expect(isEventSupported('click', document)).to.be(true);24 });25 it('returns false when no event name is provided', function() {26 expect(isEventSupported()).to.be(false);27 });28 it('returns true when the event exists', function() {29 expect(isEventSupported('click')).to.be(true);30 });31 it('returns false when the event does not exists', function() {32 expect(isEventSupported('fart')).to.be(false);33 });34 describe('fallback', function() {35 var onblur = document.documentElement.onblur;36 var called;37 before(function(done) {38 try {39 // IE 7 fails if we try to delete properties that don't exist40 delete document.documentElement.onblur;41 } catch (e) {}42 requirejs.undef('isEventSupported');43 requirejs.undef('createElement');44 define('createElement', [], function() {45 return function() {46 var elm = typeof document.createElement !== 'function' ?47 document.createElement(arguments[0]) :48 document.createElement.apply(document, arguments);49 // logic added to get simulate old firefox's behavior50 if (!called) {51 try {52 delete elm.onclick;53 } catch (e) {}54 elm.setAttribute = undefined;55 called = true;56 }57 return elm;58 };59 });60 requirejs(['isEventSupported'], function(_isEventSupported) {61 isEventSupported = _isEventSupported;62 done();63 });64 });65 it('fallsback properly with no element', function() {66 expect(isEventSupported('click')).to.be(true);67 });68 it('fallsback properly when testing with a global element', function() {69 expect(isEventSupported('click', document)).to.be(true);70 });71 after(function() {72 document.documentElement.onblur = onblur;73 });74 });75 after(function() {76 cleanup();77 });...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1var isEventSupported = require('./isEventSupported');2describe('dom/isEventSupported', function () {3 it('checks if event is supported by browser', function () {4 expect(isEventSupported('click')).toBe(true);5 expect(isEventSupported('click', document.createElement('button'))).toBe(true);6 expect(isEventSupported('select')).toBe(true);7 expect(isEventSupported('select', document.createElement('input'))).toBe(true);8 expect(isEventSupported('change')).toBe(true);9 expect(isEventSupported('change', document.createElement('input'))).toBe(true);10 expect(isEventSupported('change')).toBe(true);11 expect(isEventSupported('change', document.createElement('input'))).toBe(true);12 expect(isEventSupported('submit')).toBe(true);13 expect(isEventSupported('submit', document.createElement('form'))).toBe(true);14 expect(isEventSupported('reset')).toBe(true);15 expect(isEventSupported('reset', document.createElement('form'))).toBe(true);16 expect(isEventSupported('error')).toBe(true);17 expect(isEventSupported('error', document.createElement('image'))).toBe(true);18 expect(isEventSupported('load')).toBe(true);19 expect(isEventSupported('load', document.createElement('image'))).toBe(true);20 expect(isEventSupported('abort')).toBe(true);21 expect(isEventSupported('abort', document.createElement('image'))).toBe(true);22 expect(isEventSupported('scroll')).toBe(true);23 expect(isEventSupported('scroll', window)).toBe(true);24 expect(isEventSupported('keyup')).toBe(true);25 expect(isEventSupported('keyup', document.createElement('input'))).toBe(true);26 expect(isEventSupported('something')).toBe(false);27 expect(function () {28 return isEventSupported({});29 }).toThrow(new TypeError('Expected a string for first argument'));30 });...

Full Screen

Full Screen

isEventSupported.test.js

Source:isEventSupported.test.js Github

copy

Full Screen

1/**2 * Test the isEventSupported() function in validate.js to make sure the expected values are returned.3 *4 * @deprecated Will be removed in v4.5 */6import { isEventSupported } from "../../src/validate";7describe("isEventSupported", () => {8 // Mock console.error.9 console.error = jest.fn();10 // Declare element.11 document.body.innerHTML = "<button></button>";12 const element = document.querySelector("button");13 test("returns true when checking for 'mouseup' on a <button>", () => {14 expect(isEventSupported("mouseup", element)).toBeTrue();15 });16 test("returns false when checking for an unsupported event on a <button>", () => {17 expect(isEventSupported("unsupportedEvent", element)).toBeFalse();18 });19 test("returns false when checking for an invalid event on a <button>", () => {20 expect(isEventSupported(123, element)).toBeFalse();21 });22 test("returns false when checking for 'mouseup' on a non-HTMLElement", () => {23 expect(isEventSupported("mouseup", "button")).toBeFalse();24 });25 test("returns false when checking for an invalid event on a non-HTMLElement", () => {26 expect(isEventSupported(123, "button")).toBeFalse();27 });...

Full Screen

Full Screen

validator.test.js

Source:validator.test.js Github

copy

Full Screen

2describe('Validator#isEventSupported', () => {3 let validator = new Validator()4 test('Returns correctly with one supported event', () => {5 validator.supportedEvents = ['issues.opened']6 expect(validator.isEventSupported('pull_request.opened')).toBe(false)7 expect(validator.isEventSupported('issues.opened')).toBe(true)8 })9 test('Returns correctly with more than one supported event', () => {10 validator.supportedEvents = ['issues.opened', 'pull_request.opened']11 expect(validator.isEventSupported('pull_request.labeled')).toBe(false)12 expect(validator.isEventSupported('issues.opened')).toBe(true)13 expect(validator.isEventSupported('pull_request.opened')).toBe(true)14 })15 test('Returns correctly with a wildcard in the event name', () => {16 validator.supportedEvents = ['issues.opened', 'pull_request.*']17 expect(validator.isEventSupported('pull_request.labeled')).toBe(true)18 expect(validator.isEventSupported('issues.milestoned')).toBe(false)19 })...

Full Screen

Full Screen

action.test.js

Source:action.test.js Github

copy

Full Screen

2describe('Action#isEventSupported', () => {3 let action = new Action()4 test('Returns correctly with one supported event', () => {5 action.supportedEvents = ['issues.opened']6 expect(action.isEventSupported('pull_request.opened')).toBe(false)7 expect(action.isEventSupported('issues.opened')).toBe(true)8 })9 test('Returns correctly with more than one supported event', () => {10 action.supportedEvents = ['issues.opened', 'pull_request.opened']11 expect(action.isEventSupported('pull_request.labeled')).toBe(false)12 expect(action.isEventSupported('issues.opened')).toBe(true)13 expect(action.isEventSupported('pull_request.opened')).toBe(true)14 })15 test('Returns correctly with a wildcard in the event name', () => {16 action.supportedEvents = ['issues.opened', 'pull_request.*']17 expect(action.isEventSupported('pull_request.labeled')).toBe(true)18 expect(action.isEventSupported('issues.milestoned')).toBe(false)19 })...

Full Screen

Full Screen

EventPluginHub-test.js

Source:EventPluginHub-test.js Github

copy

Full Screen

1/**2 * Copyright 2013-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 *9 * @emails react-core10 */11'use strict';12jest.mock('isEventSupported');13describe('EventPluginHub', () => {14 var EventPluginHub;15 var isEventSupported;16 beforeEach(() => {17 jest.resetModuleRegistry();18 EventPluginHub = require('EventPluginHub');19 isEventSupported = require('isEventSupported');20 isEventSupported.mockReturnValueOnce(false);21 });22 it('should prevent non-function listeners', () => {23 expect(function() {24 EventPluginHub.putListener(1, 'onClick', 'not a function');25 }).toThrowError(26 'Expected onClick listener to be a function, instead got type string'27 );28 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('@playwright/test/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const isSupported = await isEventSupported(page, 'click');8 console.log(isSupported);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('@playwright/test/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const isSupported = await isEventSupported(page, 'pointerdown');8 console.log(isSupported);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('playwright/lib/server/supplements/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.click('input[name="q"]');7 await page.keyboard.type('playwright');8 const isSupported = await page.evaluate(isEventSupported, 'keydown');9 console.log('Is keydown event supported?', isSupported);10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('playwright/lib/server/supplements/utils/supplementUtils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 console.log(await isEventSupported(page, 'click'));8 await browser.close();9})();10What is the difference between the JavaScript method call() and apply()?11How to use the JavaScript method call()?12What is the difference between the JavaScript method bind() and call()?13How to use the JavaScript method bind()?14How to use the JavaScript method apply()?15How to use the JavaScript method call()?16What is the difference between the JavaScript method bind() and call()?17How to use the JavaScript method bind()?18How to use the JavaScript method apply()?19How to use the JavaScript method call()?20How to use the JavaScript method bind()?21How to use the JavaScript method apply()?22How to use the JavaScript method call()?23How to use the JavaScript method bind()?24How to use the JavaScript method apply()?25« How to use the JavaScript method call()?26How to use the JavaScript method bind()? »

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('@playwright/test/lib/utils/utils');2test('isEventSupported', async ({ page }) => {3 const isSupported = await page.evaluate(isEventSupported, 'click');4 console.log(isSupported);5});6@dhruv-makwana I think this is expected. The isEventSupported() function is only used to check if the event is supported in the browser. If you want to check if the event is supported on the element, you can use page.$eval() :7const isSupported = await page.$eval('body', (element) => {8 return 'click' in element;9});10console.log(isSupported);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isEventSupported } from 'playwright/lib/server/dom.js';2const eventSupported = await isEventSupported(page, 'click');3console.log(eventSupported);4const { isEventSupported } = require('playwright/lib/server/dom');5const eventSupported = await isEventSupported(page, 'click');6console.log(eventSupported);7const { isEventSupported } = require('playwright/lib/server/dom');8(async () => {9 const eventSupported = await isEventSupported(page, 'click');10 console.log(eventSupported);11})();12const { isEventSupported } = require('playwright/lib/server/dom');13(async () => {14 const eventSupported = await isEventSupported(page, 'click');15 console.log(eventSupported);16})();17const { isEventSupported } = require('playwright/lib/server/dom');18(async () => {19 const eventSupported = await isEventSupported(page, 'click');20 console.log(eventSupported);21})();22const { isEventSupported } = require('playwright/lib/server/dom');23(async () => {24 const eventSupported = await isEventSupported(page, 'click');25 console.log(eventSupported);26})();27const { isEventSupported } = require('playwright/lib/server/dom');28(async () => {29 const eventSupported = await isEventSupported(page, 'click');30 console.log(eventSupported);31})();32const { isEventSupported } = require('playwright/lib/server/dom');33(async () => {34 const eventSupported = await isEventSupported(page, 'click');35 console.log(eventSupported);36})();37const { isEventSupported } = require('playwright/lib/server/dom');38(async () => {39 const eventSupported = await isEventSupported(page, 'click');40 console.log(eventSupported);41})();42const { isEventSupported } = require('playwright/lib/server/dom');43(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEventSupported } = require('playwright/lib/internal/utils/utils');2console.log(isEventSupported('click', document.body));3const { isEventSupported } = require('playwright/lib/internal/utils/utils');4console.log(isEventSupported('click', document.body));5const { isEventSupported } = require('playwright/lib/internal/utils/utils');6console.log(isEventSupported('click', document.body));7const { isEventSupported } = require('playwright/lib/internal/utils/utils');8console.log(isEventSupported('click', document.body));9const { isEventSupported } = require('playwright/lib/internal/utils/utils');10console.log(isEventSupported('click', document.body));11const { isEventSupported } = require('playwright/lib/internal/utils/utils');12console.log(isEventSupported('click', document.body));13const { isEventSupported } = require('playwright/lib/internal/utils/utils');14console.log(isEventSupported('click', document.body));15const { isEventSupported } = require('playwright/lib/internal/utils/utils');16console.log(isEventSupported('click', document.body));17const { isEventSupported } = require('playwright/lib/internal/utils/utils');18console.log(isEventSupported('click', document.body));19const { isEventSupported } = require('playwright/lib/internal/utils/utils');20console.log(isEventSupported('click', document.body));21const { isEventSupported } = require('playwright/lib/internal/utils/utils');22console.log(isEventSupported('click', document.body));

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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