How to use getListener method in Playwright Internal

Best JavaScript code snippet using playwright-internal

EventMapTree.js

Source:EventMapTree.js Github

copy

Full Screen

...5 it('sets a listener object at the root', function() {6 var tree = new EventMapTree();7 var listener = {};8 tree.setListener([], listener);9 expect(tree.getListener([])).equal(listener);10 expect(tree.children).equal(null);11 });12 it('setting returns the previous listener', function() {13 var tree = new EventMapTree();14 var listener1 = 'listener1';15 var listener2 = 'listener2';16 var previous = tree.setListener([], listener1);17 expect(previous).equal(null);18 expect(tree.getListener([])).equal(listener1);19 var previous = tree.setListener([], listener2);20 expect(previous).equal(listener1);21 expect(tree.getListener([])).equal(listener2);22 expect(tree.children).equal(null);23 });24 it('sets a listener object at a path', function() {25 var tree = new EventMapTree();26 var listener = {};27 tree.setListener(['colors'], listener);28 expect(tree.getListener([])).equal(null);29 expect(tree.getListener(['colors'])).equal(listener);30 });31 it('sets a listener object at a subpath', function() {32 var tree = new EventMapTree();33 var listener = {};34 tree.setListener(['colors', 'green'], listener);35 expect(tree.getListener([])).equal(null);36 expect(tree.getListener(['colors'])).equal(null);37 expect(tree.getListener(['colors', 'green'])).equal(listener);38 });39 });40 describe('destroy', function() {41 it('can be called on empty root', function() {42 var tree = new EventMapTree();43 tree.destroy();44 expect(tree.children).eql(null);45 });46 it('removes nodes up to root', function() {47 var tree = new EventMapTree();48 tree.setListener(['colors', 'green'], 'listener1');49 var node = tree._getChild(['colors', 'green']);50 node.destroy();51 expect(tree.children).eql(null);52 });53 it('can be called on child node repeatedly', function() {54 var tree = new EventMapTree();55 tree.setListener(['colors', 'green'], 'listener1');56 var node = tree._getChild(['colors', 'green']);57 node.destroy();58 node.destroy();59 });60 it('does not remove parent nodes with existing listeners', function() {61 var tree = new EventMapTree();62 tree.setListener(['colors'], 'listener1');63 tree.setListener(['colors', 'green'], 'listener2');64 var node = tree._getChild(['colors', 'green']);65 node.destroy();66 node.destroy();67 expect(tree.getListener(['colors'])).eql('listener1');68 });69 it('does not remove parent nodes with other children', function() {70 var tree = new EventMapTree();71 tree.setListener(['colors', 'red'], 'listener1');72 tree.setListener(['colors', 'green'], 'listener2');73 var node = tree._getChild(['colors', 'green']);74 node.destroy();75 node.destroy();76 expect(tree.getListener(['colors', 'red'])).eql('listener1');77 });78 });79 describe('deleteListener', function() {80 it('can be called before setListener', function() {81 var tree = new EventMapTree();82 tree.deleteListener(['colors', 'green']);83 expect(tree.getListener(['colors', 'green'])).equal(null);84 expect(tree.children).equal(null);85 });86 it('deletes listener at root', function() {87 var tree = new EventMapTree();88 var listener = {};89 tree.setListener([], listener);90 expect(tree.getListener([])).equal(listener);91 var previous = tree.deleteListener([]);92 expect(previous).equal(listener);93 expect(tree.getListener([])).equal(null);94 });95 it('deletes listener at subpath', function() {96 var tree = new EventMapTree();97 var listener = {};98 tree.setListener(['colors', 'green'], listener);99 expect(tree.getListener(['colors', 'green'])).equal(listener);100 var previous = tree.deleteListener(['colors', 'green']);101 expect(previous).equal(listener);102 expect(tree.children).equal(null);103 });104 it('deletes listener with remaining children', function() {105 var tree = new EventMapTree();106 var listener1 = 'listener1';107 var listener2 = 'listener2';108 tree.setListener(['colors'], listener1);109 tree.setListener(['colors', 'green'], listener2);110 expect(tree.getListener(['colors'])).equal(listener1);111 expect(tree.getListener(['colors', 'green'])).equal(listener2);112 tree.deleteListener(['colors']);113 expect(tree.getListener(['colors'])).equal(null);114 expect(tree.getListener(['colors', 'green'])).equal(listener2);115 });116 it('deletes listener with remaining peers', function() {117 var tree = new EventMapTree();118 var listener1 = 'listener1';119 var listener2 = 'listener2';120 tree.setListener(['colors', 'red'], listener1);121 tree.setListener(['colors', 'green'], listener2);122 expect(tree.getListener(['colors', 'red'])).equal(listener1);123 expect(tree.getListener(['colors', 'green'])).equal(listener2);124 tree.deleteListener(['colors', 'red']);125 expect(tree.getListener(['colors', 'red'])).equal(null);126 expect(tree.getListener(['colors', 'green'])).equal(listener2);127 });128 });129 describe('deleteAllListeners', function() {130 it('can be called on empty root', function() {131 var tree = new EventMapTree();132 tree.deleteAllListeners([]);133 });134 it('can be called on missing node', function() {135 var tree = new EventMapTree();136 tree.deleteAllListeners(['colors', 'green']);137 });138 it('deletes all listeners and children when called on root', function() {139 var tree = new EventMapTree();140 var listener1 = 'listener1';141 var listener2 = 'listener2';142 var listener3 = 'listener3';143 tree.setListener([], listener1);144 tree.setListener(['colors'], listener2);145 tree.setListener(['colors', 'green'], listener3);146 tree.deleteAllListeners([]);147 expect(tree.getListener([])).equal(null);148 expect(tree.children).equal(null);149 });150 it('deletes listeners and descendent children on path', function() {151 var tree = new EventMapTree();152 var listener1 = 'listener1';153 var listener2 = 'listener2';154 var listener3 = 'listener3';155 tree.setListener([], listener1);156 tree.setListener(['colors'], listener2);157 tree.setListener(['colors', 'green'], listener3);158 tree.deleteAllListeners(['colors']);159 expect(tree.getListener([])).equal(listener1);160 expect(tree.children).equal(null);161 });162 });163 describe('getAffectedListeners', function() {164 it('returns empty array without listeners', function() {165 var tree = new EventMapTree();166 var affected = tree.getAffectedListeners([]);167 expect(affected).eql([]);168 });169 it('returns empty array on path without node', function() {170 var tree = new EventMapTree();171 var affected = tree.getAffectedListeners(['colors', 'green']);172 expect(affected).eql([]);173 });...

Full Screen

Full Screen

element.js

Source:element.js Github

copy

Full Screen

...53 registerNode(this.docId, node)54 }55 if (node.nodeType === 1) {56 insertIndex(node, this.pureChildren, this.pureChildren.length)57 const listener = getListener(this.docId)58 if (listener) {59 return listener.addElement(node, this.ref, -1)60 }61 }62 }63 else {64 moveIndex(node, this.children, this.children.length, true)65 if (node.nodeType === 1) {66 const index = moveIndex(node, this.pureChildren, this.pureChildren.length)67 const listener = getListener(this.docId)68 if (listener && index >= 0) {69 return listener.moveElement(node.ref, this.ref, index)70 }71 }72 }73 },74 /**75 * Insert a node before specified node.76 * @param {object} node77 * @param {object} before78 * @return {undefined | number} the signal sent by native79 */80 insertBefore (node, before) {81 if (node.parentNode && node.parentNode !== this) {82 return83 }84 if (node === before || (node.nextSibling && node.nextSibling === before)) {85 return86 }87 if (!node.parentNode) {88 linkParent(node, this)89 insertIndex(node, this.children, this.children.indexOf(before), true)90 if (this.docId) {91 registerNode(this.docId, node)92 }93 if (node.nodeType === 1) {94 const pureBefore = nextElement(before)95 const index = insertIndex(96 node,97 this.pureChildren,98 pureBefore99 ? this.pureChildren.indexOf(pureBefore)100 : this.pureChildren.length101 )102 const listener = getListener(this.docId)103 if (listener) {104 return listener.addElement(node, this.ref, index)105 }106 }107 }108 else {109 moveIndex(node, this.children, this.children.indexOf(before), true)110 if (node.nodeType === 1) {111 const pureBefore = nextElement(before)112 const index = moveIndex(113 node,114 this.pureChildren,115 pureBefore116 ? this.pureChildren.indexOf(pureBefore)117 : this.pureChildren.length118 )119 const listener = getListener(this.docId)120 if (listener && index >= 0) {121 return listener.moveElement(node.ref, this.ref, index)122 }123 }124 }125 },126 /**127 * Insert a node after specified node.128 * @param {object} node129 * @param {object} after130 * @return {undefined | number} the signal sent by native131 */132 insertAfter (node, after) {133 if (node.parentNode && node.parentNode !== this) {134 return135 }136 if (node === after || (node.previousSibling && node.previousSibling === after)) {137 return138 }139 if (!node.parentNode) {140 linkParent(node, this)141 insertIndex(node, this.children, this.children.indexOf(after) + 1, true)142 /* istanbul ignore else */143 if (this.docId) {144 registerNode(this.docId, node)145 }146 if (node.nodeType === 1) {147 const index = insertIndex(148 node,149 this.pureChildren,150 this.pureChildren.indexOf(previousElement(after)) + 1151 )152 const listener = getListener(this.docId)153 /* istanbul ignore else */154 if (listener) {155 return listener.addElement(node, this.ref, index)156 }157 }158 }159 else {160 moveIndex(node, this.children, this.children.indexOf(after) + 1, true)161 if (node.nodeType === 1) {162 const index = moveIndex(163 node,164 this.pureChildren,165 this.pureChildren.indexOf(previousElement(after)) + 1166 )167 const listener = getListener(this.docId)168 if (listener && index >= 0) {169 return listener.moveElement(node.ref, this.ref, index)170 }171 }172 }173 },174 /**175 * Remove a child node, and decide whether it should be destroyed.176 * @param {object} node177 * @param {boolean} preserved178 */179 removeChild (node, preserved) {180 if (node.parentNode) {181 removeIndex(node, this.children, true)182 if (node.nodeType === 1) {183 removeIndex(node, this.pureChildren)184 const listener = getListener(this.docId)185 if (listener) {186 listener.removeElement(node.ref)187 }188 }189 }190 if (!preserved) {191 node.destroy()192 }193 },194 /**195 * Clear all child nodes.196 */197 clear () {198 const listener = getListener(this.docId)199 /* istanbul ignore else */200 if (listener) {201 this.pureChildren.forEach(node => {202 listener.removeElement(node.ref)203 })204 }205 this.children.forEach(node => {206 node.destroy()207 })208 this.children.length = 0209 this.pureChildren.length = 0210 },211 /**212 * Set an attribute, and decide whether the task should be send to native.213 * @param {string} key214 * @param {string | number} value215 * @param {boolean} silent216 */217 setAttr (key, value, silent) {218 if (this.attr[key] === value && silent !== false) {219 return220 }221 this.attr[key] = value222 const listener = getListener(this.docId)223 if (!silent && listener) {224 listener.setAttr(this.ref, key, value)225 }226 },227 /**228 * Set a style property, and decide whether the task should be send to native.229 * @param {string} key230 * @param {string | number} value231 * @param {boolean} silent232 */233 setStyle (key, value, silent) {234 if (this.style[key] === value && silent !== false) {235 return236 }237 this.style[key] = value238 const listener = getListener(this.docId)239 if (!silent && listener) {240 listener.setStyle(this.ref, key, value)241 }242 },243 /**244 * Set style properties from class.245 * @param {object} classStyle246 */247 setClassStyle (classStyle) {248 // reset previous class style to empty string249 for (const key in this.classStyle) {250 this.classStyle[key] = ''251 }252 Object.assign(this.classStyle, classStyle)253 const listener = getListener(this.docId)254 if (listener) {255 listener.setStyles(this.ref, this.toStyle())256 }257 },258 /**259 * Add an event handler.260 * @param {string} event type261 * @param {function} event handler262 */263 addEvent (type, handler) {264 if (!this.event[type]) {265 this.event[type] = handler266 const listener = getListener(this.docId)267 if (listener) {268 listener.addEvent(this.ref, type)269 }270 }271 },272 /**273 * Remove an event handler.274 * @param {string} event type275 */276 removeEvent (type) {277 if (this.event[type]) {278 delete this.event[type]279 const listener = getListener(this.docId)280 if (listener) {281 listener.removeEvent(this.ref, type)282 }283 }284 },285 /**286 * Fire an event manually.287 * @param {string} event type288 * @param {function} event handler289 * @return {} anything returned by handler function290 */291 fireEvent (type, e) {292 const handler = this.event[type]293 if (handler) {...

Full Screen

Full Screen

smpl.Ecb.js

Source:smpl.Ecb.js Github

copy

Full Screen

...44 assert.equals(Object.keys(smpl).sort(), ['Ecb', 'global']);45 });46 47 test('standard usage', function() {48 ecb.addListener('test', getListener('a'));49 ecb.fire('test');50 assert.equals(calls, [{key: 'a', args: ['test'], scope: defaultScope}]);51 ecb.removeListener('test', getListener('a'));52 ecb.fire('test');53 assert.equals(calls, [{key: 'a', args: ['test'], scope: defaultScope}]);54 });55 56 test('standard usage with scope', function() {57 ecb.addListener('test', getListener('a'), getScope('a'));58 ecb.fire('test');59 assert.equals(calls, [{key: 'a', args: ['test'], scope: getScope('a')}]);60 ecb.removeListener('test', getListener('a'), getScope('a'));61 ecb.fire('test');62 assert.equals(calls, [{key: 'a', args: ['test'], scope: getScope('a')}]);63 });64 65 test('fire with arguments', function() {66 ecb.addListener('test', getListener('a'));67 ecb.addListener('test', getListener('b'), getScope('b'));68 ecb.fire('test', 'with', 'some', 'arguments');69 assert.equals(calls, [70 {key: 'a', args: ['test', 'with', 'some', 'arguments'], scope: defaultScope},71 {key: 'b', args: ['test', 'with', 'some', 'arguments'], scope: getScope('b')}72 ]);73 });74 75 test('removeListener', function() {76 var addListeners = function(key) {77 ecb.addListener(key, getListener(key));78 ecb.addListener(key, getListener(key + key));79 ecb.addListener(key, getListener(key), getScope(key));80 ecb.addListener(key, getListener(key), getScope(key + key));81 ecb.addListener(key, getListener(key + key), getScope(key + key));82 };83 var expectedCalls = [];84 85 addListeners('a');86 ecb.removeListener('a');87 ecb.fire('a');88 assert.equals(calls, expectedCalls);89 90 addListeners('b');91 ecb.removeListener('b', getListener('b'));92 expectedCalls.push({key: 'bb', args: ['b'], scope: defaultScope});93 expectedCalls.push({key: 'bb', args: ['b'], scope: getScope('bb')});94 ecb.fire('b');95 assert.equals(calls, expectedCalls);96 97 addListeners('c');98 ecb.removeListener('c', undefined, getScope('cc'));99 expectedCalls.push({key: 'c', args: ['c'], scope: defaultScope});100 expectedCalls.push({key: 'cc', args: ['c'], scope: defaultScope});101 expectedCalls.push({key: 'c', args: ['c'], scope: getScope('c')});102 ecb.fire('c');103 assert.equals(calls, expectedCalls);104 105 addListeners('d');106 ecb.removeListener('d', undefined, undefined);107 ecb.fire('d');108 assert.equals(calls, expectedCalls);109 110 ecb.removeListener('x');111 ecb.fire('x');112 assert.equals(calls, expectedCalls);113 });114 115 test('removeListener during fire', function() {116 var listener = function() {117 ecb.removeListener('test', listener);118 getListener('a').apply(this, arguments);119 };120 121 ecb.addListener('test', listener);122 ecb.addListener('test', getListener('b'));123 ecb.fire('test');124 ecb.fire('test');125 assert.equals(calls, [126 {key: 'a', args: ['test'], scope: defaultScope},127 {key: 'b', args: ['test'], scope: defaultScope},128 {key: 'b', args: ['test'], scope: defaultScope}129 ]);130 });131 132 test('pause', function() {133 ecb.addListener('test', getListener('a'));134 ecb.pause();135 ecb.fire('test');136 assert.equals(calls, []);137 ecb.pause();138 ecb.resume();139 ecb.addListener('test', getListener('b'), getScope('a'));140 ecb.fire('test');141 assert.equals(calls, []);142 ecb.resume();143 144 assert.equals(calls, [145 {key: 'a', args: ['test'], scope: defaultScope},146 {key: 'b', args: ['test'], scope: getScope('a')},147 {key: 'a', args: ['test'], scope: defaultScope},148 {key: 'b', args: ['test'], scope: getScope('a')}149 ]);150 });151 152 test('pause during resume', function() {153 var pause = function() {154 ecb.pause();155 ecb.fire('test');156 };157 var expectedCalls = [];158 159 ecb.pause();160 ecb.addListener('test', pause);161 ecb.addListener('test', getListener('a'));162 ecb.fire('test');163 assert.equals(calls, expectedCalls);164 165 ecb.resume();166 expectedCalls.push({key: 'a', args: ['test'], scope: defaultScope});167 assert.equals(calls, expectedCalls);168 169 ecb.resume();170 expectedCalls.push({key: 'a', args: ['test'], scope: defaultScope});171 assert.equals(calls, expectedCalls);172 });173 174 test('multiple resume', function() {175 // Resuming and not paused ecb should have no effect176 ecb.resume();177 ecb.resume();178 ecb.pause();179 ecb.addListener('test', getListener('a'));180 ecb.fire('test');181 assert.equals(calls, []);182 ecb.resume();183 assert.equals(calls, [{key: 'a', args: ['test'], scope: defaultScope}]);184 });185 186 test('reset', function() {187 ecb.addListener('test', getListener('a'));188 ecb.pause();189 190 ecb.reset();191 192 // Test that ecb is empty193 ecb.fire('test');194 assert.equals(calls, []);195 196 // Test that ecb is not paused197 ecb.addListener('test', getListener('b'));198 ecb.fire('test');199 assert.equals(calls, [{key: 'b', args: ['test'], scope: defaultScope}]);200 });201 });...

Full Screen

Full Screen

remove.spec.js

Source:remove.spec.js Github

copy

Full Screen

...14 var b2 = s.add(l2);15 s.remove(l1);16 expect( s.getNumListeners() ).toBe( 1 );17 expect( b1.listener ).toBeUndefined();18 expect( b1.getListener() ).toBeUndefined();19 expect( b1.context ).toBeUndefined();20 s.remove(l2);21 expect( s.getNumListeners() ).toBe( 0 );22 expect( b2.listener ).toBeUndefined();23 expect( b2.getListener() ).toBeUndefined();24 expect( b2.context ).toBeUndefined();25 expect( s.getNumListeners() ).toBe( 0 );26 s.dispatch();27 });28 it('should not fail if called twice in a row', function () {29 var s = this.signal;30 var l = function(){expect(null).toEqual('fail: ');};31 s.add(l);32 s.remove(l);33 s.remove(l);34 expect( s.getNumListeners() ).toBe( 0 );35 s.dispatch();36 });37 it('should throw error if trying to remove a listener that isn\'t a function', function () {38 var s = this.signal;39 var l1 = function(){expect(null).toEqual('fail: ');};40 var b1 = s.add(l1);41 expect( function(){ s.remove() } ).toThrow( 'listener is a required param of remove() and should be a Function.' );42 expect( function(){ s.remove(123) } ).toThrow( 'listener is a required param of remove() and should be a Function.' );43 expect( function(){ s.remove(true) } ).toThrow( 'listener is a required param of remove() and should be a Function.' );44 expect( function(){ s.remove('bar') } ).toThrow( 'listener is a required param of remove() and should be a Function.' );45 expect( s.getNumListeners() ).toBe( 1 );46 });47 });48 describe('removeAll()', function () {49 it('should remove all listeners', function () {50 var s = this.signal;51 var b1 = s.add(function(){expect(null).toEqual('fail: ')});52 var b2 = s.add(function(){expect(null).toEqual('fail: ')});53 var b3 = s.addOnce(function(){expect(null).toEqual('fail: ')});54 var b4 = s.add(function(){expect(null).toEqual('fail: ')});55 var b5 = s.addOnce(function(){expect(null).toEqual('fail: ')});56 expect( s.getNumListeners() ).toBe( 5 );57 s.removeAll();58 expect( s.getNumListeners() ).toBe( 0 );59 expect( b1.listener ).toBeUndefined();60 expect( b1.getListener() ).toBeUndefined();61 expect( b1.context ).toBeUndefined();62 expect( b2.listener ).toBeUndefined();63 expect( b2.getListener() ).toBeUndefined();64 expect( b2.context ).toBeUndefined();65 expect( b3.listener ).toBeUndefined();66 expect( b3.getListener() ).toBeUndefined();67 expect( b3.context ).toBeUndefined();68 expect( b4.listener ).toBeUndefined();69 expect( b4.getListener() ).toBeUndefined();70 expect( b4.context ).toBeUndefined();71 expect( b5.listener ).toBeUndefined();72 expect( b5.getListener() ).toBeUndefined();73 expect( b5.context ).toBeUndefined();74 s.dispatch();75 s.removeAll();76 expect( s.getNumListeners() ).toBe( 0 );77 });78 });79 describe('diff context', function () {80 it('should remove listener based on context', function () {81 var s = this.signal;82 var l1 = function(){expect(null).toEqual('fail: ');};83 var obj = {};84 var b1 = s.add(l1);85 var b2 = s.add(l1, obj);86 expect( s.getNumListeners() ).toBe( 2 );87 expect( b1.context ).toBeUndefined();88 expect( b1.getListener() ).toBe( l1 );89 expect( b2.context ).toBe( obj );90 expect( b2.getListener() ).toBe( l1 );91 s.remove(l1, obj);92 expect( b2.context ).toBeUndefined();93 expect( b2.getListener() ).toBeUndefined();94 expect( b1.context ).toBeUndefined();95 expect( b1.getListener() ).toBe( l1 );96 expect( s.getNumListeners() ).toBe( 1 );97 s.remove(l1);98 expect( s.getNumListeners() ).toBe( 0 );99 s.dispatch();100 });101 });...

Full Screen

Full Screen

RegisterControl.js

Source:RegisterControl.js Github

copy

Full Screen

...43 * @param {Array} data 44 */45 signup(data) {46 if (data.firstname === '')47 this.getListener().emit(RegisterControl.signup_error, 'Enter firstname')48 else if (data.lastname === '')49 this.getListener().emit(RegisterControl.signup_error, 'Enter lastname for user')50 else if (data.username === '')51 this.getListener().emit(RegisterControl.signup_error, 'Enter Username for user')52 else if (data.password === '')53 this.getListener().emit(RegisterControl.signup_error, 'Enter password, the password must have 8 characters')54 else if (data.password.length < 8)55 this.getListener().emit(RegisterControl.signup_error, 'the entered password is too short, password must have 8 characters or numbers')56 else if (data.email === '')57 this.getListener().emit(RegisterControl.signup_error, 'Enter email for user')58 else {59 AccountControl.newInstance().isUsernameExists(data.username, (result) => {60 if (result) {61 this.getListener().emit(RegisterControl.signup_error, 'the entered username already use from another user')62 return63 }64 AccountControl.newInstance().isEmailExists(data.email, (result) => {65 if (result) {66 this.getListener().emit(RegisterControl.signup_error, 'the entered email already use from another user')67 return68 }69 signupComplete(data, this.Client, this.getListener())70 })71 })72 }73 /**74 * @param {MongoClient} client 75 * @param {EventEmitter} listener 76 */77 function signupComplete(data, client, listener) {78 client.connect(err => {79 const collection = client.db("accounts").collection("users")80 try {81 collection.insertOne({82 name: data.firstname,83 lastname: data.lastname,...

Full Screen

Full Screen

ConditionalChangeListenerTest.js

Source:ConditionalChangeListenerTest.js Github

copy

Full Screen

...19 assertEquals("1a", 0, this.m_nChangeInvocationCount);20};21ConditionalChangeListenerTest.prototype.testAddingAChangeListenerDoesntCauseAChangeInvocation = function()22{23 this.m_oChangeProperty.addListener(this.getListener(true));24 assertEquals(0, this.m_nChangeInvocationCount);25};26ConditionalChangeListenerTest.prototype.testAddingANodeListChangeListenerDoesntCauseAChangeInvocation = function()27{28 this.m_oChangeNodeList.addListener(this.getListener(true));29 assertEquals(0, this.m_nChangeInvocationCount);30};31ConditionalChangeListenerTest.prototype.testThatAnImmediateChangeInvocationOccursIfTheInvokeImmediatelyFlagIsSet = function()32{33 this.m_oChangeProperty.addListener(this.getListener(true), true);34 assertEquals(1, this.m_nChangeInvocationCount);35};36ConditionalChangeListenerTest.prototype.testThatAnImmediateChangeInvocationHasNoEffectIfTheConditionPropertyIsNotMet = function()37{38 this.m_oConditionProperty.setValue(false);39 this.m_oChangeProperty.addListener(this.getListener(true), true);40 assertEquals(0, this.m_nChangeInvocationCount);41};42ConditionalChangeListenerTest.prototype.testThatSettingTheSameValueAsBeforeHasNoEffect = function()43{44 this.m_oChangeProperty.addListener(this.getListener(true));45 46 this.m_oChangeProperty.setValue(99);47 assertEquals(0, this.m_nChangeInvocationCount);48};49ConditionalChangeListenerTest.prototype.testThatChangesToThePropertyWhileTheConditionPropertyIsMetIncreasesInvocationCount = function()50{51 this.m_oChangeProperty.addListener(this.getListener(true));52 53 this.m_oChangeProperty.setValue(100);54 assertEquals(1, this.m_nChangeInvocationCount);55};56ConditionalChangeListenerTest.prototype.testThatChangesToTheNodeListWhileTheConditionPropertyIsMetIncreasesInvocationCount = function()57{58 this.m_oChangeNodeList.addListener(this.getListener(true));59 60 this.m_oChangeNodeList.updateList([]);61 assertEquals(1, this.m_nChangeInvocationCount);62};63ConditionalChangeListenerTest.prototype.testThatChangesToThePropertyWhileTheConditionPropertyAreNotMetAreIgnored = function()64{65 this.m_oChangeProperty.addListener(this.getListener(true));66 67 this.m_oConditionProperty.setValue(false);68 this.m_oChangeProperty.setValue(100);69 assertEquals(0, this.m_nChangeInvocationCount);70};71ConditionalChangeListenerTest.prototype.testThatIgnoredChangesAreSentOnceTheConitionIsMetAgain = function()72{73 this.m_oChangeProperty.addListener(this.getListener(true));74 75 this.m_oConditionProperty.setValue(false);76 this.m_oChangeProperty.setValue(100);77 this.m_oConditionProperty.setValue(true);78 assertEquals(1, this.m_nChangeInvocationCount);79};80ConditionalChangeListenerTest.prototype.testThatOfflineChangeInvocationStillFiresForValuesThatCanBeCooercedToTheSameValue = function()81{82 this.m_oChangeProperty.setValue(null);83 this.m_oChangeProperty.addListener(this.getListener(true));84 85 this.m_oConditionProperty.setValue(false);86 this.m_oChangeProperty.setValue(undefined);87 this.m_oConditionProperty.setValue(true);88 assertEquals(1, this.m_nChangeInvocationCount);...

Full Screen

Full Screen

Messenger.spec.js

Source:Messenger.spec.js Github

copy

Full Screen

...9});10describe('Messenger', () => {11 test('selector', done => {12 const m = Messenger('projectId', document.querySelector('#iframe_id').contentWindow);13 expect(m.getListener()).toBe(null);14 m.once('*', message => {15 expect(message).toEqual({ hello: 'world' });16 expect(m.channelListeners.length).toBe(0);17 done();18 });19 m.send('a.b', { hello: 'world' });20 expect(m.getListener()).toBe(null);21 });22 test('once', done => {23 expect(messenger.getListener()).toBe(null);24 messenger.once('*', message => {25 expect(message).toEqual({ hello: 'world' });26 expect(messenger.channelListeners.length).toBe(0);27 done();28 });29 messenger.send('a.b', { hello: 'world' });30 expect(messenger.getListener()).toBe(null);31 });32 test('on', done => {33 expect(messenger.getListener()).toBe(null);34 messenger.on('a.b', message => {35 expect(message).toEqual({ hello: 'world' });36 expect(messenger.channelListeners.length).toBe(1);37 done();38 });39 messenger.send('a.b', { hello: 'world' });40 expect(messenger.getListener()).not.toBe(null);41 });42 test('off', done => {43 messenger.on('a.b', message => {44 expect(message).toEqual({ hello: 'world' });45 expect(messenger.channelListeners.length).toBe(1);46 done();47 });48 messenger.send('a.*', { hello: 'world' });49 messenger.off(); // 取消所有50 expect(messenger.getListener()).toBe(null);51 });52 test('namespace not match', done => {53 messenger.on('a.b', message => {54 done();55 });56 messenger.send('a.b', { hello: 'world' });57 messenger.send('a.c', { hello: 'alipay' });58 });59 // when no listener, remove message listener60 test('message listener', () => {61 expect(messenger.getListener()).toBe(null);62 const l1 = jest.fn();63 const l2 = jest.fn();64 messenger.on('a.b', l1);65 expect(messenger.getListener()).not.toBe(null);66 expect(messenger.channelListeners.length).toBe(1);67 messenger.once('a', l2);68 expect(messenger.getListener()).not.toBe(null);69 expect(messenger.channelListeners.length).toBe(2);70 messenger.off('a.b', l1);71 expect(messenger.getListener()).not.toBe(null);72 expect(messenger.channelListeners.length).toBe(1);73 messenger.off('a.b', l2);74 expect(messenger.getListener()).not.toBe(null);75 expect(messenger.channelListeners.length).toBe(1);76 messenger.off('a', l2);77 expect(messenger.getListener()).toBe(null);78 expect(messenger.channelListeners.length).toBe(0);79 });80 // exception81 test('exception', () => {82 expect(() => {83 Messenger('');84 }).not.toThrow();85 expect(() => {86 Messenger('').send('a', 1);87 }).toThrow('Messenger\'s target should has `postMessage` function.');88 });...

Full Screen

Full Screen

extended.js

Source:extended.js Github

copy

Full Screen

...4 _classCallCheck(this, EventDispatcher);5 this.eventMap = {};6 }7 EventDispatcher.prototype.on = function on(eventName, handler) {8 var listeners = this.getListener(eventName);9 if (!listeners) {10 this.eventMap[eventName] = [handler];11 } else if (listeners.indexOf(handler) === -1) {12 listeners.push(handler);13 }14 return this;15 };16 EventDispatcher.prototype.once = function once(eventName, handler) {17 var _this = this;18 var f2 = function f2(e) {19 handler(e);20 _this.off(eventName, f2);21 };22 return this.on(eventName, f2);23 };24 EventDispatcher.prototype.off = function off(eventName, handler) {25 if (!handler) {26 return this.removeAllListener(eventName);27 }28 var listeners = this.getListener(eventName);29 if (listeners) {30 var i = listeners.indexOf(handler);31 if (i > -1) {32 listeners.splice(i, 1);33 if (!listeners.length) {34 delete this.eventMap[eventName];35 }36 }37 }38 return this;39 };40 EventDispatcher.prototype.removeAllListener = function removeAllListener(eventName) {41 if (!eventName) {42 if (this.eventMap) {43 var keys = Object.keys(this.eventMap);44 for (var i = 0; i < keys.length; i++) {45 this.removeAllListener(keys[i]);46 }47 }48 return;49 }50 var listeners = this.getListener(eventName);51 if (listeners) {52 this.eventMap[eventName].length = 0;53 delete this.eventMap[eventName];54 }55 return this;56 };57 EventDispatcher.prototype.trigger = function trigger(eventType) {58 var eventObject = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};59 var listeners = this.getListener(eventType);60 if (listeners) {61 eventObject.type = eventType;62 eventObject.target = eventObject.target || this;63 for (var i = 0, l = listeners.length; i < l; i++) {64 listeners[i](eventObject);65 }66 }67 return this;68 };69 EventDispatcher.prototype.getListener = function getListener(eventName) {70 var result = this.eventMap ? this.eventMap[eventName] : null;71 return result || null;72 };73 EventDispatcher.prototype.destroy = function destroy() {74 this.removeAllListener();75 this.eventMap = null;76 this.destroyed = true;77 return this;78 };79 return EventDispatcher;80}();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('@playwright/test/lib/test');2const listener = getListener();3listener.on('test', (test, result) => {4 if (result.status === 'failed') {5 console.log('Test failed: ' + test.title);6 }7});8listener.on('testEnd', (test, result) => {9 if (result.status === 'passed') {10 console.log('Test passed: ' + test.title);11 }12});13listener.on('testEnd', (test, result) => {14 if (result.status === 'skipped') {15 console.log('Test skipped: ' + test.title);16 }17});18listener.on('testEnd', (test, result) => {19 if (result.status === 'expected') {20 console.log('Test expected: ' + test.title);21 }22});23listener.on('testEnd', (test, result) => {24 if (result.status === 'unexpected') {25 console.log('Test unexpected: ' + test.title);26 }27});28listener.on('testEnd', (test, result) => {29 if (result.status === 'timedOut') {30 console.log('Test timedOut: ' + test.title);31 }32});33const { getListener } = require('@playwright/test/lib/test');34const listener = getListener();35listener.on('test', (test, result) => {36 if (result.status === 'failed') {37 console.log('Test failed: ' + test.title);38 }39});40listener.on('testEnd', (test, result) => {41 if (result.status === 'passed') {42 console.log('Test passed: ' + test.title);43 }44});45listener.on('testEnd', (test, result) => {46 if (result.status === 'skipped') {47 console.log('Test skipped: ' + test.title);48 }49});50listener.on('testEnd', (test, result) => {51 if (result.status === 'expected') {52 console.log('Test expected: ' + test.title);53 }54});55listener.on('testEnd', (test, result) => {56 if (result.status === 'unexpected') {57 console.log('Test unexpected: ' + test.title);58 }59});60listener.on('testEnd', (test, result) => {61 if (result.status === 'timedOut

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('@playwright/test/lib/server/listener');2const listener = getListener();3const { getBrowserServer } = require('@playwright/test/lib/server/browserServer');4const browserServer = getBrowserServer();5const { getBrowserContext } = require('@playwright/test/lib/server/browserContext');6const browserContext = getBrowserContext();7const { getBrowser } = require('@playwright/test/lib/server/browser');8const browser = getBrowser();9const { getPlaywright } = require('@playwright/test/lib/server/playwright');10const playwright = getPlaywright();11const { getBrowserType } = require('@playwright/test/lib/server/browserType');12const browserType = getBrowserType();13const { getBrowserName } = require('@playwright/test/lib/server/browserName');14const browserName = getBrowserName();15const { getLaunchOptions } = require('@playwright/test/lib/server/launchOptions');16const launchOptions = getLaunchOptions();17const { getBrowserOptions } = require('@playwright/test/lib/server/browserOptions');18const browserOptions = getBrowserOptions();19const { getTestInfo } = require('@playwright/test/lib/server/testInfo');20const testInfo = getTestInfo();21const { getTestFixtures } = require('@playwright/test/lib/server/testFixtures');22const testFixtures = getTestFixtures();23const { getTestType } = require('@playwright/test/lib/server/testType');24const testType = getTestType();25const { getTestName } = require('@playwright/test/lib/server/testName');26const testName = getTestName();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const listener = getListener();3const events = listener.getEvents();4const event = listener.getEvent(2);5const lastEvent = listener.getLastEvent();6const lastEvents = listener.getLastEvents(2);7- [Playwright Recorder](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('@playwright/test/lib/runner');2const listener = getListener();3listener.on('test', (test, result) => {4 console.log(test.title);5 console.log(result.status);6});7listener.on('test', (test, result) => {8 console.log(test.title);9 console.log(result.status);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('@playwright/test/lib/test');2const listener = getListener();3const { test, expect } = require('@playwright/test');4test('test', async ({ page }) => {5 listener.on('test', (test, result) => {6 console.log('test completed', test.title);7 });8 await page.waitForSelector('text=Get started');9 await expect(page).toHaveText('text=Get started');10});11- **`on('test', (test, result) => {})`**12- **`on('testskip', (test) => {})`**13- **`on('testfail', (test, result) => {})`**14- **`on('teststep', (test, result) => {})`**15- **`on('teststepstart', (test, result) => {})`**16- **`on('teststepend', (test, result) => {})`**17- **`on('workercreated', (worker) => {})`**18- **`on('workerdestroyed', (worker) => {})`**19- **`on('fixture', (test, fixture, result) => {})`**

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('playwright/lib/server/browserType');2const listener = getListener();3listener.on('response', (response) => {4 console.log(response.url());5});6const { chromium } = require('playwright');7(async () => {8 const browser = await chromium.launch();9 const page = await browser.newPage();10 await page.screenshot({ path: 'google.png' });11 await browser.close();12})();13const { chromium } = require('playwright');14describe('Playwright', () => {15 it('should launch browser', async () => {16 const browser = await chromium.launch();17 const page = await browser.newPage();18 await page.screenshot({ path: 'google.png' });19 await browser.close();20 });21});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('playwright/lib/utils/events');2const listener = getListener(browserContext, 'page');3const listener = getListener(browser, 'close');4const listener = getListener(page, 'close');5const listener = getListener(frame, 'close');6Licensed under the [MIT License](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require("@playwright/test/lib/server/traceViewer/webSocketTransport");2const listener = getListener();3listener.on("message", (message) => {4 console.log(message);5});6We welcome all contributions! Please read our [Contributions Guide](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getListener } = require('playwright/lib/internal/transport');2const { chromium } = require('playwright');3const browser = await chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const listener = getListener(page);7listener.on('console', (e) => {8 console.log(e.text());9});10await browser.close();

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