Best JavaScript code snippet using wpt
App.js
Source:App.js
1jest.disableAutomock();2import * as constants from '../../../shared/constants';3import App, {flattenIds} from '../App';4const fooRoot = {5 id: 'foo'6};7describe('flattenIds', () => {8 test('should flatten object into an array', () => {9 expect(10 flattenIds({11 one: {12 childComponents: [13 {14 childComponents: [15 {16 expanded: false,17 id: 518 }19 ],20 expanded: true,21 id: 222 }23 ],24 expanded: true,25 id: 126 },27 two: {28 childComponents: [29 {30 expanded: false,31 id: 332 }33 ],34 expanded: false,35 id: 436 }37 })38 ).toMatchSnapshot();39 });40});41describe('App', () => {42 test('should render', () => {43 const component = new App({44 port: {45 onMessage: {46 addListener: jest.fn()47 }48 }49 });50 component.state.rootComponents = {foo: fooRoot};51 jest.runAllTimers();52 expect(component).toMatchSnapshot();53 });54 test('should detach', () => {55 const component = new App({56 port: {57 onMessage: {58 addListener: jest.fn()59 }60 }61 });62 component.detach();63 jest.runAllTimers();64 expect(component).toMatchSnapshot();65 });66 test('should add root to state', () => {67 const component = new App({68 port: {69 onMessage: {70 addListener: jest.fn()71 }72 }73 });74 expect(component.state.rootComponents).toEqual({});75 component.addRootComponent(fooRoot);76 expect(component.state.rootComponents).toEqual({foo: fooRoot});77 });78 test('should check id detached component is a root', () => {79 const component = new App({80 port: {81 onMessage: {82 addListener: jest.fn()83 }84 }85 });86 component.state.rootComponents = {foo: fooRoot};87 component.checkIfRootDetached('foo');88 expect(component.state.rootComponents).toEqual({});89 });90 test('should call appropriate method for each arrow key', () => {91 const component = new App({92 onComponentExpand: jest.fn(),93 onSelectedChange: jest.fn(),94 port: {95 onMessage: {96 addListener: jest.fn()97 }98 }99 });100 component.setState({101 rootComponents: {102 0: {103 id: 'bar'104 },105 1: {106 id: 'test'107 },108 2: {109 id: 'foo'110 }111 },112 selectedComponent: {id: 'test'}113 });114 jest.runAllTimers();115 component.handleKeys({key: 'ArrowDown', preventDefault: jest.fn()});116 expect(component.props.onSelectedChange).toHaveBeenCalled();117 component.handleKeys({key: 'ArrowUp', preventDefault: jest.fn()});118 expect(component.props.onSelectedChange).toHaveBeenCalled();119 component.handleKeys({key: 'ArrowLeft', preventDefault: jest.fn()});120 expect(component.props.onSelectedChange).toHaveBeenCalled();121 component.handleKeys({key: 'ArrowRight', preventDefault: jest.fn()});122 expect(component.props.onSelectedChange).toHaveBeenCalled();123 });124 test('should set column width', () => {125 const component = new App({126 port: {127 onMessage: {128 addListener: jest.fn()129 }130 }131 });132 component.handleResize({clientX: 100});133 expect(component.state.firstColumnWidth).toEqual(100);134 });135 describe('processMessage', () => {136 test('should call `checkIfRootDetached`', () => {137 const component = new App({138 port: {139 onMessage: {140 addListener: jest.fn()141 }142 }143 });144 const spy = jest.fn();145 component.checkIfRootDetached = spy;146 component.processMessage({data: {}, type: constants.DETACHED});147 expect(spy).toBeCalled();148 });149 test('should call `updateRootComponent`', () => {150 const component = new App({151 port: {152 onMessage: {153 addListener: jest.fn()154 }155 }156 });157 const spy = jest.fn();158 component.updateRootComponent = spy;159 component.processMessage({data: {}, type: constants.UPDATE});160 expect(spy).toBeCalled();161 });162 test('should set selectedComponent', () => {163 const component = new App({164 port: {165 onMessage: {166 addListener: jest.fn()167 }168 }169 });170 component.processMessage({data: fooRoot, type: constants.SELECTED});171 expect(component.state.selectedComponent).toBe(fooRoot);172 });173 test('should call `addRootComponent`', () => {174 const component = new App({175 port: {176 onMessage: {177 addListener: jest.fn()178 }179 }180 });181 const spy = jest.fn();182 component.addRootComponent = spy;183 component.processMessage({data: {}, type: constants.NEW_ROOT});184 expect(spy).toBeCalled();185 });186 test('should emit console.log', () => {187 const component = new App({188 port: {189 onMessage: {190 addListener: jest.fn()191 }192 }193 });194 const logVal = console.log;195 console.log = jest.fn();196 component.processMessage({data: {}, type: 'bar'});197 expect(console.log).toBeCalled();198 console.log = logVal;199 });200 });201 test('should emit console.log', () => {202 const component = new App({203 port: {204 onMessage: {205 addListener: jest.fn()206 }207 }208 });209 const spy = jest.fn();210 component.flashNode = spy;211 component.processMessage({data: {}, type: constants.RENDERED});212 expect(spy).toBeCalled();213 });214 test('should reset rootComponents state', () => {215 const component = new App({216 port: {217 onMessage: {218 addListener: jest.fn()219 }220 }221 });222 component.state.rootComponents = {foo: 'bar'};223 component.resetRoots();224 expect(component.state.rootComponents).toEqual({});225 });226 test('should update component', () => {227 const component = new App({228 port: {229 onMessage: {230 addListener: jest.fn()231 }232 }233 });234 component.state.rootComponents = {foo: fooRoot};235 component.updateRootComponent({...fooRoot, name: 'fooRoot'});236 expect(component.state.rootComponents['foo'].name).toEqual('fooRoot');237 });238 test('should add/remove `flash` class', () => {239 const component = new App({240 port: {241 onMessage: {242 addListener: jest.fn()243 }244 }245 });246 component.addFlash(component.element);247 expect(component.element.classList).toContain('flash');248 component.removeFlash(component.element);249 expect(component.element.classList).not.toContain('flash');250 });251 test('should add/remove `flash` class', () => {252 const component = new App({253 port: {254 onMessage: {255 addListener: jest.fn()256 }257 }258 });259 const initialStub = document.querySelector;260 document.querySelector = jest.fn(() => true);261 component.addFlash = jest.fn();262 component.removeFlash = jest.fn();263 component.flashNode('testComponent');264 jest.runAllTimers();265 expect(component.addFlash).toBeCalled();266 expect(component.removeFlash).toBeCalled();267 component.state.freezeUpdates = true;268 jest.runAllTimers();269 component.flashNode('testComponent');270 component.removeFlash.mockReset();271 expect(component.removeFlash).not.toBeCalled();272 document.querySelector = initialStub;273 });274 test('should toggle freezeUpdates', () => {275 const component = new App({276 port: {277 onMessage: {278 addListener: jest.fn()279 }280 }281 });282 expect(component.state.freezeUpdates).toEqual(false);283 component.handleFreezeToggle({target: {checked: true}});284 expect(component.state.freezeUpdates).toEqual(true);285 component._pendingFlashRemovals = [document.createElement('div')];286 component.handleFreezeToggle({target: {checked: false}});287 expect(component.state.freezeUpdates).toEqual(false);288 });...
NodeList-static-length-tampered.js
Source:NodeList-static-length-tampered.js
1"use strict";2function makeStaticNodeList(length) {3 const fooRoot = document.createElement("div");4 for (var i = 0; i < length; i++) {5 const el = document.createElement("span");6 el.className = "foo";7 fooRoot.append(el);8 }9 document.body.append(fooRoot);10 return fooRoot.querySelectorAll(".foo");11}12const indexOfNodeList = new Function("nodeList", `13 const __cacheBust = ${Math.random()};14 const el = nodeList[50];15 let index = -1;16 for (var i = 0; i < 1e5 / 2; i++) {17 for (var j = 0; j < nodeList.length; j++) {18 if (nodeList[j] === el) {19 index = j;20 break;21 }22 }23 }24 return index;25`);26const arrayIndexOfNodeList = new Function("nodeList", `27 const __cacheBust = ${Math.random()};28 const el = nodeList[50];29 const {indexOf} = Array.prototype;30 for (var i = 0; i < 1e5; i++) {31 var index = indexOf.call(nodeList, el);32 }33 return index;...
Using AI Code Generation
1var wptools = require('wptools');2wptools.fooRoot();3var wptools = require('wptools');4wptools.fooRoot();5var wptools = require('wptools');6wptools.fooRoot();7var wptools = require('wptools');8wptools.fooRoot();9var wptools = require('wptools');10wptools.fooRoot();11var wptools = require('wptools');12wptools.fooRoot();13var wptools = require('wptools');14wptools.fooRoot();15var wptools = require('wptools');16wptools.fooRoot();17var wptools = require('wptools');18wptools.fooRoot();19var wptools = require('wptools');20wptools.fooRoot();21var wptools = require('wptools');22wptools.fooRoot();23var wptools = require('wptools');24wptools.fooRoot();25var wptools = require('wptools');26wptools.fooRoot();27var wptools = require('wptools');28wptools.fooRoot();29var wptools = require('
Using AI Code Generation
1var wptools = require('wptools');2var fooRoot = wptools.fooRoot;3fooRoot('Barack Obama');4var wptools = require('wptools');5var fooRoot = wptools.fooRoot;6fooRoot('Barack Obama');7var wptools = require('wptools');8var fooRoot = wptools.fooRoot;9fooRoot('Barack Obama');10var wptools = require('wptools');11var fooRoot = wptools.fooRoot;12fooRoot('Barack Obama');13var wptools = require('wptools');14var fooRoot = wptools.fooRoot;15fooRoot('Barack Obama');16var wptools = require('wptools');17var fooRoot = wptools.fooRoot;18fooRoot('Barack Obama');19var wptools = require('wptools');20var fooRoot = wptools.fooRoot;21fooRoot('Barack Obama');22var wptools = require('wptools');23var fooRoot = wptools.fooRoot;24fooRoot('Barack Obama');25var wptools = require('wptools');26var fooRoot = wptools.fooRoot;27fooRoot('Barack Obama');28var wptools = require('wptools');29var fooRoot = wptools.fooRoot;30fooRoot('Barack Obama');31var wptools = require('wptools');32var fooRoot = wptools.fooRoot;33fooRoot('Barack Obama');
Using AI Code Generation
1var wpt = require('webpagetest');2var fooRoot = wpt.fooRoot;3fooRoot('test');4var wpt = require('webpagetest');5var fooRoot = wpt.fooRoot;6fooRoot('test2');7var wpt = require('webpagetest');8var fooRoot = wpt.fooRoot;9fooRoot('test3');10var wpt = require('webpagetest');11var fooRoot = wpt.fooRoot;12fooRoot('test4');13var wpt = require('webpagetest');14var fooRoot = wpt.fooRoot;15fooRoot('test5');16var wpt = require('webpagetest');17var fooRoot = wpt.fooRoot;18fooRoot('test6');19var wpt = require('webpagetest');20var fooRoot = wpt.fooRoot;21fooRoot('test7');22var wpt = require('webpagetest');23var fooRoot = wpt.fooRoot;24fooRoot('test8');25var wpt = require('webpagetest');26var fooRoot = wpt.fooRoot;27fooRoot('test9');28var wpt = require('webpagetest');29var fooRoot = wpt.fooRoot;30fooRoot('test10');31var wpt = require('webpagetest');32var fooRoot = wpt.fooRoot;33fooRoot('test11');34var wpt = require('webpagetest');
Using AI Code Generation
1var wptools = require('wptools');2wptools.fooRoot();3If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:4var wptools = require('wptools');5If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:6var wptools = require('wptools');7If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:8var wptools = require('wptools');9If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:10var wptools = require('wptools');11If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:12var wptools = require('wptools');13If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:14var wptools = require('wptools');15If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:16var wptools = require('wptools');17If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:18var wptools = require('wptools');19If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:20var wptools = require('wptools');21If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:22var wptools = require('wptools');23If you want to use wptools.fooRoot() in another file, you need to make sure that the file has the following line at the top:24var wptools = require('wptools');
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!!