Best JavaScript code snippet using wpt
controller_observer.js
Source:controller_observer.js
1QUnit.test( "controller observer tests - observe", assert => {2 App.Ticket.refresh([{3 id: 1,4 title: 'ticket',5 state_id: 1,6 customer_id: 33,7 organization_id: 1,8 owner_id: 1,9 preferences: { a: 1, b: 2 },10 }])11 var observer1 = new App.ControllerObserver({12 object_id: 1,13 template: 'version',14 observe: {15 title: true,16 preferences: true,17 },18 })19 var ticket = App.Ticket.find(1)20 assert.equal(false, observer1.hasChanged(ticket))21 // track title changes22 ticket.title = 'title 2'23 assert.equal(true, observer1.hasChanged(ticket))24 assert.equal(false, observer1.hasChanged(ticket))25 ticket.title = undefined26 assert.equal(true, observer1.hasChanged(ticket))27 assert.equal(false, observer1.hasChanged(ticket))28 ticket.title = 'title 3'29 assert.equal(true, observer1.hasChanged(ticket))30 assert.equal(false, observer1.hasChanged(ticket))31 // track no owner_id changes32 ticket.owner_id = 233 assert.equal(false, observer1.hasChanged(ticket))34 assert.equal(false, observer1.hasChanged(ticket))35 // track preferences changes36 ticket.preferences['a'] = 337 assert.equal(true, observer1.hasChanged(ticket))38 assert.equal(false, observer1.hasChanged(ticket))39 ticket.preferences['c'] = 340 assert.equal(true, observer1.hasChanged(ticket))41 assert.equal(false, observer1.hasChanged(ticket))42 // track no new_attribute1 changes43 ticket.new_attribute1 = 'na 3'44 assert.equal(false, observer1.hasChanged(ticket))45 assert.equal(false, observer1.hasChanged(ticket))46 ticket.new_attribute2 = function() { console.log(1) }47 assert.equal(false, observer1.hasChanged(ticket))48 assert.equal(false, observer1.hasChanged(ticket))49 ticket.new_attribute2 = function() { console.log(2) }50 assert.equal(false, observer1.hasChanged(ticket))51 assert.equal(false, observer1.hasChanged(ticket))52 // track title changes53 ticket.title = function() { console.log(1) }54 assert.equal(true, observer1.hasChanged(ticket))55 assert.equal(false, observer1.hasChanged(ticket))56 ticket.title = function() { console.log(2) }57 assert.equal(false, observer1.hasChanged(ticket))58 assert.equal(false, observer1.hasChanged(ticket))59 ticket.title = 160 assert.equal(true, observer1.hasChanged(ticket))61 assert.equal(false, observer1.hasChanged(ticket))62});63QUnit.test( "controller observer tests - observeNot", assert => {64 App.Ticket.refresh([{65 id: 2,66 title: 'ticket',67 state_id: 1,68 customer_id: 33,69 organization_id: 1,70 owner_id: 1,71 preferences: { a: 1, b: 2 },72 }])73 var observer1 = new App.ControllerObserver({74 object_id: 2,75 template: 'version',76 observeNot: {77 title: true,78 preferences: true,79 },80 })81 var ticket = App.Ticket.find(2)82 assert.equal(false, observer1.hasChanged(ticket))83 // track no title changes84 ticket.title = 'title 2'85 assert.equal(false, observer1.hasChanged(ticket))86 assert.equal(false, observer1.hasChanged(ticket))87 // track owner_id changes88 ticket.owner_id = 289 assert.equal(true, observer1.hasChanged(ticket))90 assert.equal(false, observer1.hasChanged(ticket))91 ticket.owner_id = undefined92 assert.equal(true, observer1.hasChanged(ticket))93 assert.equal(false, observer1.hasChanged(ticket))94 ticket.owner_id = 395 assert.equal(true, observer1.hasChanged(ticket))96 assert.equal(false, observer1.hasChanged(ticket))97 // track no preferences changes98 ticket.preferences['a'] = 399 assert.equal(false, observer1.hasChanged(ticket))100 assert.equal(false, observer1.hasChanged(ticket))101 ticket.preferences['c'] = 3102 assert.equal(false, observer1.hasChanged(ticket))103 assert.equal(false, observer1.hasChanged(ticket))104 // track preferences2 changes105 ticket.preferences2 = {}106 assert.equal(true, observer1.hasChanged(ticket))107 assert.equal(false, observer1.hasChanged(ticket))108 ticket.preferences2['a'] = 3109 assert.equal(true, observer1.hasChanged(ticket))110 assert.equal(false, observer1.hasChanged(ticket))111 ticket.preferences2['a'] = 2112 assert.equal(true, observer1.hasChanged(ticket))113 assert.equal(false, observer1.hasChanged(ticket))114 ticket.preferences2['c'] = 3115 assert.equal(true, observer1.hasChanged(ticket))116 assert.equal(false, observer1.hasChanged(ticket))117 // track new_attribute1 changes118 ticket.new_attribute1 = 'na 3'119 assert.equal(true, observer1.hasChanged(ticket))120 assert.equal(false, observer1.hasChanged(ticket))121 // track no new_attribute2 changes (because of function content)122 ticket.new_attribute2 = function() { console.log(1) }123 assert.equal(false, observer1.hasChanged(ticket))124 assert.equal(false, observer1.hasChanged(ticket))125 ticket.new_attribute2 = function() { console.log(2) }126 assert.equal(false, observer1.hasChanged(ticket))127 assert.equal(false, observer1.hasChanged(ticket))128 // track owner_id changes (pnly if content has no function content)129 ticket.owner_id = function() { console.log(1) }130 assert.equal(true, observer1.hasChanged(ticket))131 assert.equal(false, observer1.hasChanged(ticket))132 ticket.owner_id = function() { console.log(2) }133 assert.equal(false, observer1.hasChanged(ticket))134 assert.equal(false, observer1.hasChanged(ticket))135 ticket.owner_id = 1136 assert.equal(true, observer1.hasChanged(ticket))137 assert.equal(false, observer1.hasChanged(ticket))...
recentRegistrationsService_01_tests.js
Source:recentRegistrationsService_01_tests.js
1describe("recentRegistrationsService", function() {2 'use strict';3 var service,4 observer1,5 observer2;6 beforeEach(function() {7 service = Conference.recentRegistrationsService();8 observer1 = {9 update: function update() { }10 };11 observer2 = {12 update: function update() { }13 };14 });15 afterEach(function() {16 service.stopPolling();17 service.clearObservers();18 });19 describe("addObserver(observer) ë° hasObserver(observer)", function() {20 describe("ë¨ì¼ ê´ì°°ì", function() {21 it("ê´ì°°ìê° ì¶ê°ëì§ ììë¤ë©´ hasObserverë false를 ë°ííë¤", function() {22 expect(service.hasObserver(observer1)).toBe(false);23 });24 it("ê´ì°°ìê° ì¶ê°ëë¤ë©´ hasObserverë true를 ë°ííë¤", function() {25 service.addObserver(observer1);26 expect(service.hasObserver(observer1)).toBe(true);27 });28 });29 describe("ë¤ì¤ ê´ì°°ì", function() {30 it("ê´ì°°ìê° ì¶ê°ëì§ ììë¤ë©´ false를 ë°ííë¤", function() {31 service.addObserver(observer1);32 expect(service.hasObserver(observer2)).toBe(false);33 });34 it("ê´ì°°ì를 ì¶ê°íë©´ ê°ê°ì ëí´ true를 ë°ííë¤", function() {35 service.addObserver(observer1);36 service.addObserver(observer2);37 expect(service.hasObserver(observer1)).toBe(true);38 expect(service.hasObserver(observer2)).toBe(true);39 });40 });41 });42 describe("removeObserver(observer)", function() {43 describe("ë¨ì¼ ê´ì°°ì", function() {44 it("ì¶ê°íì§ ìì ê´ì°°ìì ëí´ìë ì무 ì¼ë íì§ ìëë¤", function() {45 // observer1ì ì¶ê°íë¤46 service.addObserver(observer1);47 // observer2를 ìì íë ¤ê³ íë¤48 service.removeObserver(observer2);49 expect(service.hasObserver(observer1)).toBe(true);50 expect(service.hasObserver(observer2)).toBe(false);51 });52 53 it("ì¶ê°í ê´ì°°ì를 ìì íë¤", function() {54 service.addObserver(observer1);55 expect(service.hasObserver(observer1)).toBe(true);56 service.removeObserver(observer1);57 expect(service.hasObserver(observer1)).toBe(false);58 });59 });60 describe("ë¤ì¤ ê´ì°°ì", function() {61 it("주ì´ì§ ê´ì°°ìë§ ìì íë¤", function() {62 service.addObserver(observer1);63 service.addObserver(observer2);64 service.removeObserver(observer2);65 expect(service.hasObserver(observer1)).toBe(true);66 expect(service.hasObserver(observer2)).toBe(false);67 });68 });69 });70 describe("updateObservers(newAttendee)", function() {71 var registration;72 beforeEach(function() {73 registration = { };74 spyOn(observer1, "update");75 spyOn(observer2, "update");76 });77 describe("ë¨ì¼ ê´ì°°ì", function() {78 it("ê´ì°°ìì update í¨ì를 ì¤ííë¤", function() {79 service.addObserver(observer1);80 service.updateObservers(registration);81 expect(observer1.update).toHaveBeenCalledWith(registration);82 });83 it("ìì ë ê´ì°°ìì update í¨ìë ì¤ííì§ ìëë¤", function() {84 service.addObserver(observer1);85 service.removeObserver(observer1);86 service.updateObservers(registration);87 expect(observer1.update).not.toHaveBeenCalledWith(registration);88 });89 });90 describe("ë¤ì¤ ê´ì°°ì", function() {91 it("ê´ì°°ìì update í¨ì를 ì¤ííë¤", function() {92 service.addObserver(observer1);93 service.addObserver(observer2);94 service.updateObservers(registration);95 expect(observer1.update).toHaveBeenCalledWith(registration);96 expect(observer2.update).toHaveBeenCalledWith(registration);97 });98 it("ìì ë ê´ì°°ìì update í¨ìë ì¤ííì§ ìëë¤", function() {99 service.addObserver(observer1);100 service.addObserver(observer2);101 service.removeObserver(observer2);102 service.updateObservers(registration);103 expect(observer1.update).toHaveBeenCalledWith(registration);104 expect(observer2.update).not.toHaveBeenCalledWith(registration);105 });106 });107 });108 describe("ê·ì½ ê°ì (ConferenceContractRegistry를 ì¬ì©íê³ ìì§ ìì ê²½ì° ì¤í¨íë¤)", function() {109 it("observer를 ddObserver(observer)ì ë£ì´ì¤ì¼ íë¤", function() {110 expect(function shouldThrow() {111 service.addObserver({});112 }).toThrow();113 });114 });...
recentRegistrationsService_initialTests.js
Source:recentRegistrationsService_initialTests.js
1describe("recentRegistrationsService", function() {2 'use strict';3 var service,4 observer1,5 observer2;6 beforeEach(function() {7 service = Conference.recentRegistrationsService();8 observer1 = {9 update: function update() { }10 };11 observer2 = {12 update: function update() { }13 };14 });15 afterEach(function() {16 service.stopPolling();17 service.clearObservers();18 });19 describe("addObserver(observer) ë° hasObserver(observer)", function() {20 describe("ë¨ì¼ ê´ì°°ì", function() {21 it("ê´ì°°ìê° ì¶ê°ëì§ ììë¤ë©´ hasObserverë false를 ë°ííë¤", function() {22 expect(service.hasObserver(observer1)).toBe(false);23 });24 it("ê´ì°°ìê° ì¶ê°ëë¤ë©´ hasObserverë true를 ë°ííë¤", function() {25 service.addObserver(observer1);26 expect(service.hasObserver(observer1)).toBe(true);27 });28 });29 describe("ë¤ì¤ ê´ì°°ì", function() {30 it("ê´ì°°ìê° ì¶ê°ëì§ ììë¤ë©´ false를 ë°ííë¤", function() {31 service.addObserver(observer1);32 expect(service.hasObserver(observer2)).toBe(false);33 });34 it("ê´ì°°ì를 ì¶ê°íë©´ ê°ê°ì ëí´ true를 ë°ííë¤", function() {35 service.addObserver(observer1);36 service.addObserver(observer2);37 expect(service.hasObserver(observer1)).toBe(true);38 expect(service.hasObserver(observer2)).toBe(true);39 });40 });41 });42 describe("removeObserver(observer)", function() {43 describe("ë¨ì¼ ê´ì°°ì", function() {44 it("ì¶ê°íì§ ìì ê´ì°°ìì ëí´ìë ì무 ì¼ë íì§ ìëë¤", function() {45 // observer1ì ì¶ê°íë¤46 service.addObserver(observer1);47 // observer2를 ìì íë ¤ê³ íë¤48 service.removeObserver(observer2);49 expect(service.hasObserver(observer1)).toBe(true);50 expect(service.hasObserver(observer2)).toBe(false);51 });52 it("ì¶ê°í ê´ì°°ì를 ìì íë¤", function() {53 service.addObserver(observer1);54 expect(service.hasObserver(observer1)).toBe(true);55 service.removeObserver(observer1);56 expect(service.hasObserver(observer1)).toBe(false);57 });58 });59 describe("ë¤ì¤ ê´ì°°ì", function() {60 it("주ì´ì§ ê´ì°°ìë§ ìì íë¤", function() {61 service.addObserver(observer1);62 service.addObserver(observer2);63 service.removeObserver(observer2);64 expect(service.hasObserver(observer1)).toBe(true);65 expect(service.hasObserver(observer2)).toBe(false);66 });67 });68 });69 describe("updateObservers(newAttendee)", function() {70 var registration;71 beforeEach(function() {72 registration = { };73 spyOn(observer1, "update");74 spyOn(observer2, "update");75 });76 describe("ë¨ì¼ ê´ì°°ì", function() {77 it("ê´ì°°ìì update í¨ì를 ì¤ííë¤", function() {78 service.addObserver(observer1);79 service.updateObservers(registration);80 expect(observer1.update).toHaveBeenCalledWith(registration);81 });82 it("ìì ë ê´ì°°ìì update í¨ìë ì¤ííì§ ìëë¤", function() {83 service.addObserver(observer1);84 service.removeObserver(observer1);85 service.updateObservers(registration);86 expect(observer1.update).not.toHaveBeenCalledWith(registration);87 });88 });89 90 describe("ë¤ì¤ ê´ì°°ì", function() {91 it("ê´ì°°ìì update í¨ì를 ì¤ííë¤", function() {92 service.addObserver(observer1);93 service.addObserver(observer2);94 service.updateObservers(registration);95 expect(observer1.update).toHaveBeenCalledWith(registration);96 expect(observer2.update).toHaveBeenCalledWith(registration);97 });98 it("ìì ë ê´ì°°ìì update í¨ìë ì¤ííì§ ìëë¤", function() {99 service.addObserver(observer1);100 service.addObserver(observer2);101 service.removeObserver(observer2);102 service.updateObservers(registration);103 expect(observer1.update).toHaveBeenCalledWith(registration);104 expect(observer2.update).not.toHaveBeenCalledWith(registration);105 });106 });107 });...
Using AI Code Generation
1function observer1() {2 return new Promise((resolve, reject) => {3 var observer = new PerformanceObserver((list) => {4 var entries = list.getEntries();5 for (var i = 0; i < entries.length; i++) {6 if (entries[i].name === "first-paint") {7 resolve(entries[i].startTime);8 }9 }10 });11 observer.observe({ entryTypes: ["paint"] });12 });13}14function observer2() {15 return new Promise((resolve, reject) => {16 var observer = new PerformanceObserver((list) => {17 var entries = list.getEntries();18 for (var i = 0; i < entries.length; i++) {19 if (entries[i].name === "first-contentful-paint") {20 resolve(entries[i].startTime);21 }22 }23 });24 observer.observe({ entryTypes: ["paint"] });25 });26}27function observer3() {28 return new Promise((resolve, reject) => {29 var observer = new PerformanceObserver((list) => {30 var entries = list.getEntries();31 for (var i = 0; i < entries.length; i++) {32 if (entries[i].name === "first-meaningful-paint") {33 resolve(entries[i].startTime);34 }35 }36 });37 observer.observe({ entryTypes: ["paint"] });38 });39}40function observer4() {41 return new Promise((resolve, reject) => {42 var observer = new PerformanceObserver((list) => {43 var entries = list.getEntries();44 for (var i = 0; i < entries.length; i++) {45 if (entries[i].name === "loadEventEnd") {46 resolve(entries[i].startTime);47 }48 }49 });50 observer.observe({ entryTypes: ["navigation"] });51 });52}53function observer5() {54 return new Promise((resolve, reject) => {55 var observer = new PerformanceObserver((list) => {56 var entries = list.getEntries();57 for (var i = 0; i < entries.length; i++) {58 if (entries[i].name === "firstInteractive") {59 resolve(entries[i].startTime);
Using AI Code Generation
1wpt.observe1(function(mutationList, observer) {2 console.log('observer1');3});4wpt.observe2(function(mutationList, observer) {5 console.log('observer2');6});7wpt.observe3(function(mutationList, observer) {8 console.log('observer3');9});10wpt.observe1(function(mutationList, observer) {11 console.log('observer1');12});13wpt.observe2(function(mutationList, observer) {14 console.log('observer2');15});16wpt.observe3(function(mutationList, observer) {17 console.log('observer3');18});19MIT © [Rajat Kumar](
Using AI Code Generation
1var observer1 = new wptObserver();2observer1.observe('test', function(arg){3 console.log('observer1: ' + arg);4});5var observer2 = new wptObserver();6observer2.observe('test', function(arg){7 console.log('observer2: ' + arg);8});9var observer3 = new wptObserver();10observer3.observe('test', function(arg){11 console.log('observer3: ' + arg);12});13var observer4 = new wptObserver();14observer4.observe('test', function(arg){15 console.log('observer4: ' + arg);16});17var observer5 = new wptObserver();18observer5.observe('test', function(arg){19 console.log('observer5: ' + arg);20});21var observer6 = new wptObserver();22observer6.observe('test', function(arg){23 console.log('observer6: ' + arg);24});25var observer7 = new wptObserver();26observer7.observe('test', function(arg){27 console.log('observer7: ' + arg);28});29var observer8 = new wptObserver();30observer8.observe('test', function(arg){31 console.log('observer8: ' + arg);32});33var observer9 = new wptObserver();34observer9.observe('test', function(arg){35 console.log('observer9: ' + arg);36});37var observer10 = new wptObserver();38observer10.observe('test', function(arg){39 console.log('observer10: ' + arg);40});41var observer11 = new wptObserver();42observer11.observe('test', function(arg
Using AI Code Generation
1wpt.observe1('test', function (data) {2});3wpt.observe2('test', function (data) {4});5wpt.observe3('test', function (data) {6});7wpt.observe4('test', function (data) {8});9wpt.observe5('test', function (data) {10});11wpt.observe6('test', function (data) {12});13wpt.observe7('test', function (data) {14});15wpt.observe8('test', function (data) {16});17wpt.observe9('test', function (data) {18});19wpt.observe10('test', function (data) {20});21wpt.observe11('test', function (data) {22});
Using AI Code Generation
1window.onload = function() {2 wptObserver1.markTime('onload');3}4wptObserver1.markTime('start');5 var wptObserver2 = new WptObserver2();6 wptObserver2.setTestName('test');7 wptObserver2.setTestPath('test');8 wptObserver2.setBrowser('Chrome');9 wptObserver2.setConnectivity('Cable');10 wptObserver2.setScript('test.js');11 wptObserver2.setVideo(true);12 wptObserver2.setVideoParams(1920, 1080, 30);13 wptObserver2.setVideoFormat('webm');14 wptObserver2.setVideoFrameRate(1);15 wptObserver2.setVideoQuality(100);16 wptObserver2.setVideoBitRate(1000000);17 wptObserver2.setVideoCodec('VP8');18 wptObserver2.setVideoBufferSize(1000000);19 wptObserver2.setVideoFileName('test');20 wptObserver2.setVideoFrameRate(1);21 wptObserver2.setVideoQuality(100);22 wptObserver2.setVideoBitRate(1000000);23 wptObserver2.setVideoCodec('VP8');24 wptObserver2.setVideoBufferSize(1000000);25 wptObserver2.setVideoFileName('test');26 wptObserver2.setVideoParams(1920, 1080, 30
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!!