Best JavaScript code snippet using wpt
suite.js
Source:suite.js
...35 m.save(null, {url:'none'});36 equal(m.unsavedAttributes(), false);37 equal(m._originalAttrs.work, '4\'33"');38 Backbone.$.ajax = oldAjax;39 m.stopTracking();40 }41 });42 test('stopTracking', 2, function() {43 var m = new Backbone.Model({id:2, name:'Marcel Duchamp'});44 45 m.startTracking();46 m.set('work', 'fountain');47 m.on('unsavedChanges', function(b, ch) {48 equal(b, false);49 equal(_.keys(ch).length, 0);50 });51 m.stopTracking();52 });53 test('restartTracking', 4, function() {54 var m = new Backbone.Model({id:2, name:'Marcel Duchamp'});55 56 m.startTracking();57 m.set('work', 'fountain');58 equal(_.keys(m.unsavedAttributes()).length, 1);59 m.on('unsavedChanges', function(b, ch) {60 equal(b, false);61 equal(_.keys(ch).length, 0);62 });63 m.restartTracking();64 equal(m.unsavedAttributes(), false);65 m.off().stopTracking();66 });67 test('resetAttributes', 3, function() {68 var m = new Backbone.Model({id:3, name:'Harmony Korine', work:'Spring Breakers'});69 70 m.startTracking();71 m.set('work', 'Gummo');72 m.on('unsavedChanges', function(b, ch) {73 equal(b, false);74 equal(_.keys(ch).length, 0);75 });76 m.resetAttributes();77 equal(m.get('work'), 'Spring Breakers');78 m.off().stopTracking();79 });80 test('unsavedAttributes', 7, function() {81 var m = new Backbone.Model({id:4, name:'Autechre'});82 83 m.startTracking();84 equal(m.unsavedAttributes(), false);85 m.set('work', 'Quartice');86 equal(m.unsavedAttributes().work, 'Quartice');87 m.set({'label':'Warp', 'instrument':'computer'});88 equal(m.unsavedAttributes().label, 'Warp');89 equal(m.unsavedAttributes().instrument, 'computer');90 equal(_.keys(m.unsavedAttributes({work:'Amber', label:'plus8', instrument:'computer'})).length, 2);91 equal(m.unsavedAttributes({work:'Amber', label:'plus8', instrument:'computer'}).work, 'Amber');92 equal(m.unsavedAttributes({work:'Amber', label:'plus8', instrument:'computer'}).label, 'plus8');93 m.stopTracking();94 });95 test('unsavedChanges', 3, function() {96 var m = new Backbone.Model({id:3, name:'Harmony Korine', work:'Spring Breakers'});97 98 m.startTracking();99 m.set('work', 'Gummo');100 m.on('unsavedChanges', function(b, ch, model) {101 equal(b, false);102 equal(_.keys(ch).length, 0);103 equal(model, m);104 });105 m.resetAttributes();106 m.off().stopTracking();107 });108 module('unload handler');109 test('window', 1, function() {110 var m = new Backbone.Model({id:5, name:'Samuel Beckett'});111 m.unsaved = {112 unloadWindowPrompt: true113 };114 // Spying/Stubbing without a fancy test framework (sue me).115 var oldUnload = window.onbeforeunload;116 window.onbeforeunload = function() {117 equal(oldUnload(), 'You have unsaved changes!');118 };119 m.startTracking();120 m.set('work', 'Molloy');121 window.onbeforeunload();122 window.onbeforeunload = oldUnload;123 m.stopTracking();124 });125 test('prompt', 1, function() {126 var m = new Backbone.Model({id:5, name:'Samuel Beckett'});127 m.unsaved = {128 prompt: 'Yes, there were times when I forgot not only who I was but that I was, forgot to be.',129 unloadWindowPrompt: true130 };131 // Spying/Stubbing without a fancy test framework ("look ma, no hands").132 var oldUnload = window.onbeforeunload;133 window.onbeforeunload = function() {134 equal(oldUnload(), 'Yes, there were times when I forgot not only who I was but that I was, forgot to be.');135 };136 m.startTracking();137 m.set('work', 'Molloy');138 window.onbeforeunload();139 window.onbeforeunload = oldUnload;140 m.stopTracking();141 });142 test('unloadWindowPrompt callback', 1, function() {143 var m = new Backbone.Model({id:5, name:'Samuel Beckett'});144 m.unsaved = {145 unloadWindowPrompt: function() { return true; }146 };147 // Spying/Stubbing without a fancy test framework (old fashioned).148 var oldUnload = window.onbeforeunload;149 window.onbeforeunload = function() {150 equal(oldUnload(), 'You have unsaved changes!');151 };152 m.startTracking();153 m.set('work', 'Molloy');154 window.onbeforeunload();155 window.onbeforeunload = oldUnload;156 m.stopTracking();157 });158 test('unloadWindowPrompt callback (function ref)', 1, function() {159 var m = new Backbone.Model({id:5, name:'Samuel Beckett'});160 m.unsaved = {161 unloadWindowPrompt: 'unload'162 };163 m.unload = function() {return true};164 // Spying/Stubbing without a fancy test framework ("you can do that?").165 var oldUnload = window.onbeforeunload;166 window.onbeforeunload = function() {167 equal(oldUnload(), 'You have unsaved changes!');168 };169 m.startTracking();170 m.set('work', 'Molloy');171 window.onbeforeunload();172 window.onbeforeunload = oldUnload;173 m.stopTracking();174 });175 test('Backbone.History.navigate', 1, function() {176 var m = new Backbone.Model({id:6, name:'Issey Miyake'});177 m.unsaved = {178 unloadRouterPrompt: true179 };180 var r = new Backbone.Router();181 Backbone.history.start();182 // Spying/Stubbing without a fancy test framework ("nice!").183 var oldConfirm = window.confirm;184 window.confirm = function(message) {185 equal(message.indexOf('You have unsaved changes!'), 0);186 };187 m.startTracking('prompt for unsaved changes!');188 189 m.set('work', 'Final Home');190 r.navigate('#test')191 m.stopTracking();192 r.navigate('#')193 window.confirm = oldConfirm;194 Backbone.history.stop();195 });196 test('unloadRouterPrompt callback (function return true)', 1, function() {197 var m = new Backbone.Model({id:6, name:'Issey Miyake'});198 m.unsaved = {199 unloadRouterPrompt: function() { return true; }200 };201 var r = new Backbone.Router();202 Backbone.history.start();203 // Spying/Stubbing without a fancy test framework (don't have a cow, man).204 var oldConfirm = window.confirm;205 window.confirm = function(message) {206 equal(message.indexOf('You have unsaved changes!'), 0);207 };208 m.startTracking('prompt for unsaved changes!');209 210 m.set('work', 'Final Home');211 r.navigate('#test')212 m.stopTracking();213 r.navigate('#')214 window.confirm = oldConfirm;215 Backbone.history.stop();216 });217 test('unloadRouterPrompt callback (function return false)', 0, function() {218 var m = new Backbone.Model({id:6, name:'Issey Miyake'});219 m.unsaved = {220 unloadRouterPrompt: function() { return false; }221 };222 var r = new Backbone.Router();223 Backbone.history.start();224 // Spying/Stubbing without a fancy test framework (bite me).225 var oldConfirm = window.confirm;226 window.confirm = function(message) {227 // It's expected that we don't get in here...228 equal(message.indexOf('You have unsaved changes!'), 0);229 };230 m.startTracking('prompt for unsaved changes!');231 232 m.set('work', 'Final Home');233 r.navigate('#test')234 m.stopTracking();235 r.navigate('#')236 window.confirm = oldConfirm;237 Backbone.history.stop();238 });239 test('trackit_silent option', 3, function() {240 var m = new Backbone.Model({id:2, name:'Burial'});241 242 m.startTracking();243 m.set('EP', 'Rival Dealer');244 var oldAjax = Backbone.$.ajax;245 Backbone.$.ajax = function(options) {246 var data = {};247 data.album = 'Untrue'248 options.success({album:'Untrue'});249 };250 m.fetch({url:'none', trackit_silent:true});251 m.set({song:'Truant'}, {trackit_silent:true});252 253 equal(m.get('album'), 'Untrue');254 equal(m.get('song'), 'Truant');255 equal(_.keys(m.unsavedAttributes()).length, 1);256 Backbone.$.ajax = oldAjax;257 m.off().stopTracking();258 });...
connect.test.ts
Source:connect.test.ts
...5 const state = createNewState();6 const mockListener = jest.fn();7 ConnectManager.startTracking(mockListener);8 state.count;9 ConnectManager.stopTracking();10 expect(mockListener).toHaveBeenCalledTimes(0);11 });12 test("it triggers when correct state is mutated", () => {13 const state = createNewState();14 const mockListener = jest.fn();15 ConnectManager.startTracking(mockListener);16 state.count;17 ConnectManager.stopTracking();18 state.count = 10;19 expect(mockListener).toHaveBeenCalledTimes(1);20 });21 test("it does not trigger when not listened state changes", () => {22 const state = createNewState();23 const mockListener = jest.fn();24 ConnectManager.startTracking(mockListener);25 state.count;26 ConnectManager.stopTracking();27 state.deep.nest = false;28 expect(mockListener).toHaveBeenCalledTimes(0);29 });30 test("it triggers only the latest subscriber", () => {31 const state = createNewState();32 const mockListener1 = jest.fn();33 const mockListener2 = jest.fn();34 ConnectManager.startTracking(mockListener1);35 ConnectManager.startTracking(mockListener2);36 state.count;37 ConnectManager.stopTracking();38 ConnectManager.stopTracking();39 state.count = 10;40 expect(mockListener1).toHaveBeenCalledTimes(0);41 expect(mockListener2).toHaveBeenCalledTimes(1);42 });43 test("it triggers only on the smallest possible change", () => {44 const state = createNewState();45 const mockListener = jest.fn();46 ConnectManager.startTracking(mockListener);47 state.array[0].amount;48 ConnectManager.stopTracking();49 state.array.push({ amount: 123 });50 expect(mockListener).toHaveBeenCalledTimes(0);51 state.array[1].amount = 333;52 expect(mockListener).toHaveBeenCalledTimes(0);53 state.array[0].amount = 111;54 expect(mockListener).toHaveBeenCalledTimes(1);55 });56 test("it triggers on object change when getting keys", () => {57 const state = createNewState();58 const mockListener = jest.fn();59 ConnectManager.startTracking(mockListener);60 Object.keys(state.users);61 ConnectManager.stopTracking();62 state.users["123-sddgsdf"] = {63 name: "asdawd",64 email: "asdsa",65 };66 expect(mockListener).toHaveBeenCalledTimes(1);67 });...
startTracking.js
Source:startTracking.js
...9}10stopTracking = require("./stopTracking.js")11const onTracking = () => {12 var player = bot.players[config.username]13 if(!player || !player.entity) return stopTracking("can't see selected player");14 timer++15 if(timer > 2400) return stopTracking("time was exceeded (2 min)")16 17 var entity = player.entity18 if(config.stopOnShift && entity.crouching) return stopTracking("total records: " + tracklist.length)19 20 var xyz = { x: +entity.position.x.toFixed(2), y: +entity.position.y.toFixed(2), z: +entity.position.z.toFixed(2) }21 var yaw = Math.floor(entity.headYaw * (180/-Math.PI) + 180)22 var pitch = Math.floor(entity.pitch * (180/-Math.PI))23 24 var last = tracklist[tracklist.length-1]25 if(last && last.xyz.x === xyz.x && last.xyz.y === xyz.y && 26 last.xyz.z === xyz.z && last.yaw === yaw && last.pitch === pitch) return;27 28 if(last && last.tick === timer - 2) fillMissing(timer, last, xyz, yaw, pitch)29 tracklist.push({ tick: timer, xyz: xyz, yaw: Math.floor(yaw), pitch: Math.floor(pitch) })30}31const fillMissing = (timer, last, xyz, yaw, pitch) => {32 tracklist.push({...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.stopTracking();3var wptoolkit = require('wptoolkit');4wptoolkit.getTrackingStatus();5var wptoolkit = require('wptoolkit');6wptoolkit.getTrackingStatus();7var wptoolkit = require('wptoolkit');8wptoolkit.getTrackingStatus();9var wptoolkit = require('wptoolkit');10wptoolkit.getTrackingStatus();11var wptoolkit = require('wptoolkit');12wptoolkit.getTrackingStatus();13var wptoolkit = require('wptoolkit');14wptoolkit.getTrackingStatus();15var wptoolkit = require('wptoolkit');16wptoolkit.getTrackingStatus();17var wptoolkit = require('wptoolkit');18wptoolkit.getTrackingStatus();19var wptoolkit = require('wptoolkit');20wptoolkit.getTrackingStatus();21var wptoolkit = require('wptoolkit');22wptoolkit.getTrackingStatus();23var wptoolkit = require('wptoolkit');24wptoolkit.getTrackingStatus();25var wptoolkit = require('wptoolkit');26wptoolkit.getTrackingStatus();27var wptoolkit = require('wptoolkit');28wptoolkit.getTrackingStatus();
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('API_KEY');3test.stopTracking('TEST_ID', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10stopTracking(testId, callback)11{ statusCode: 200, statusText: 'Ok' }12{ statusCode: 403, statusText: 'Forbidden' }13{ statusCode: 404, statusText: 'Not Found' }14{ statusCode: 500, statusText: 'Internal Server Error' }15{ statusCode: 503, statusText: 'Service Unavailable' }16{ statusCode: 504, statusText: 'Gateway Timeout' }17{ statusCode: 200, statusText: 'Ok', data: { statusCode: 200, statusText: 'Ok' } }18{ statusCode: 200, statusText: 'Ok', data: { statusCode: 403, statusText: 'Forbidden' } }19{ statusCode: 200, statusText: 'Ok', data: { statusCode: 404, statusText: 'Not Found' } }20{ statusCode: 200, statusText: 'Ok', data: { statusCode: 500, statusText: 'Internal Server Error' } }21{ statusCode: 200, statusText: 'Ok', data: { statusCode: 503, statusText: 'Service Unavailable' } }22{ statusCode: 200, statusText: 'Ok', data: { statusCode: 504, statusText: 'Gateway Timeout' } }23{ statusCode: 200, statusText: 'Ok', data: { statusCode: 200, statusText: 'Ok', data: { statusCode: 200, statusText: 'Ok' } } }24{ statusCode: 200, statusText: 'Ok', data: { statusCode: 200, statusText: 'Ok', data: { statusCode: 403, statusText: 'Forbidden' } } }25{ statusCode: 200, statusText: 'Ok', data: { statusCode: 200, statusText: 'Ok', data: { statusCode: 404, statusText: 'Not Found' } } }26{ statusCode: 200, statusText:
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.stopTracking('testId', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10Copyright (c) 2013 Brian R. Bondy
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8f5e3d9b3e3c1b6f8d6e0c6f1b6d2c2');3wpt.stopTracking(function(err, data) {4 console.log(data);5});6{7}8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org', 'A.8f5e3d9b3e3c1b6f8d6e0c6f1b6d2c2');10wpt.getLocations(function(err, data) {11 console.log(data);12});13{14 data: {15 {16 },17 {18 },19 {
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!!