Best JavaScript code snippet using wpt
tracker.test.js
Source: tracker.test.js
1/* global jest expect */23import { Tracker } from '../src';45describe('Tracker', () => {6 describe('trackEvent()', () => {7 const subscriber = jest.fn(event => event);8 subscriber.eventType = 'EVENT_TEST';910 const subscribers = [subscriber];11 const tracker = new Tracker(subscribers);1213 beforeEach(() => {14 subscriber.mockClear();15 });1617 it('should tracker have three public functions trackEvent and subscribe and on', () => {18 expect(typeof tracker.trackEvent).toBe('function');19 expect(typeof tracker.on).toBe('function');20 expect(typeof tracker.on).toBe('function');21 });2223 it('should call all the subscribers on event dispatch', () => {24 tracker.trackEvent({25 type: 'EVENT_TEST',26 data: 'hello',27 });2829 expect(subscriber).toHaveBeenCalledWith({30 type: 'EVENT_TEST',31 data: 'hello',32 }, []);33 });3435 it('should call all the subscribers on event dispatch with history', () => {36 tracker.trackEvent({37 type: 'EVENT_TEST',38 data: 'an other hello',39 });4041 expect(subscriber).toHaveBeenCalledWith({42 type: 'EVENT_TEST',43 data: 'an other hello',44 }, [{45 type: 'EVENT_TEST',46 data: 'hello',47 }]);48 });4950 it('should save the event if the subscriber returned it', () => {51 const newTracker = new Tracker(subscribers);5253 newTracker.trackEvent({54 type: 'EVENT_TEST',55 data: 're-hello',56 });5758 expect(newTracker.getHistory()).toEqual([{59 type: 'EVENT_TEST',60 data: 're-hello',61 }]);62 });6364 it('should not save the event if the subscriber return falsy value', () => {65 const newSubscriber = jest.fn(() => null);6667 const newTracker = new Tracker([newSubscriber]);6869 newTracker.trackEvent({70 type: 'EVENT_TEST',71 data: 're-hello',72 });7374 expect(newTracker.getHistory()).toEqual([]);75 });7677 it('should add the given callback to the subscribers queue', () => {78 const subscribeToAdd = jest.fn(() => null);7980 const newTracker = new Tracker([]);8182 newTracker.on('EVENT_TEST', subscribeToAdd);8384 newTracker.trackEvent({85 type: 'EVENT_TEST'86 });8788 expect(subscribeToAdd).toHaveBeenCalled();89 });9091 it('should throw if the given callback is not a function', () => {92 const subscribeToAdd = 'not a function';93 const newTracker = new Tracker([]);9495 expect(() => {newTracker.on('EVENT_TEST', subscribeToAdd)})96 .toThrow('Expected onClick listener to be a function, instead got type string');97 });9899 it('should throw if the given event type is not valid', () => {100 const subscribeToAdd = jest.fn();101 const newTracker = new Tracker([]);102103 expect(() => {newTracker.on(undefined, subscribeToAdd)})104 .toThrow('No event type is specified. (*) to listen on all events');105 });106107 it('should getHistory return the current history of tracked events', () => {108 const newTracker = new Tracker([]);109 expect(newTracker.getHistory()).toEqual([]);110 });111112 it('should call listeners with no eventType specified', () => {113 const subscriberWithNoEvent = jest.fn();114115 const newTracker = new Tracker([subscriberWithNoEvent]);116 newTracker.trackEvent({117 type: 'EVENT_TEST'118 });119120 expect(subscriberWithNoEvent).toHaveBeenCalled();121 });122123 it('should not call listeners if event dispatched have no type', () => {124 const subscriberWithNoEvent = jest.fn();125126 const newTracker = new Tracker([subscriberWithNoEvent]);127 newTracker.trackEvent({128 NoType: 'EVENT_TEST'129 });130131 expect(subscriberWithNoEvent).not.toHaveBeenCalled();132 });133 });
...
core.EventBus.js
Source: core.EventBus.js
1import EventBus from '../../src/core/EventBus';2import { EVENT_MODE_ON_START, EVENT_MODE_ON_RECEIVE } from '../../src/streaming/MediaPlayerEvents';3const chai = require('chai');4const sinon = require('sinon');5const expect = chai.expect;6const assert = chai.assert;7const context = {};8const eventBus = EventBus(context).getInstance();9describe('EventBus', function () {10 beforeEach(() => {11 eventBus.reset();12 });13 it('should throw an exception when attempting to register the on callback with an undefined type', function () {14 expect(eventBus.on.bind(eventBus)).to.throw('event type cannot be null or undefined');15 });16 it('should throw an exception when attempting to register the on callback with an undefined listener', function () {17 expect(eventBus.on.bind(eventBus, 'EVENT_TEST')).to.throw('listener must be a function: undefined');18 });19 it('should throw an exception when attempting to trigger a \'type\' payload parameter', function () {20 const spy = sinon.spy();21 eventBus.on('EVENT_TEST', spy);22 expect(eventBus.trigger.bind(eventBus, 'EVENT_TEST', { type: {}})).to.throw('\'type\' is a reserved word for event dispatching');23 });24 it('should respect priority parameter in order to notify the different listeners', function () {25 const spy = sinon.spy();26 const spy2 = sinon.spy();27 eventBus.on('EVENT_TEST', spy);28 eventBus.on('EVENT_TEST', spy2, this, { priority: EventBus.EVENT_PRIORITY_HIGH });29 eventBus.trigger('EVENT_TEST', {});30 assert.equal(spy.calledOnce, true);31 assert.equal(spy2.calledOnce, true);32 assert.equal(spy2.calledBefore(spy), true);33 });34 it('should respect mode parameter in the on function in order to trigger events according to isEventStart option in trigger function', function () {35 const spy = sinon.spy();36 const spy2 = sinon.spy();37 eventBus.on('EVENT_TEST', spy, null, { mode: EVENT_MODE_ON_START });38 eventBus.on('EVENT_TEST', spy2, null, { mode: EVENT_MODE_ON_RECEIVE });39 eventBus.trigger('EVENT_TEST', {}, { mode: EVENT_MODE_ON_START });40 eventBus.trigger('EVENT_TEST', {}, { mode: EVENT_MODE_ON_RECEIVE });41 assert.equal(spy.calledOnce, true);42 assert.equal(spy2.calledOnce, true);43 });44 it('should ignore onReceive events if no mode was specified in the callback handler', function () {45 const spy = sinon.spy();46 eventBus.on('EVENT_TEST', spy, null);47 eventBus.trigger('EVENT_TEST', {}, { mode: EVENT_MODE_ON_RECEIVE });48 assert.equal(spy.notCalled, true);49 });50 it('should trigger onStart event if no mode was specified in the callback handler', function () {51 const spy = sinon.spy();52 eventBus.on('EVENT_TEST', spy, null);53 eventBus.trigger('EVENT_TEST', {}, { mode: EVENT_MODE_ON_START });54 eventBus.trigger('EVENT_TEST', {}, { mode: EVENT_MODE_ON_RECEIVE });55 assert.equal(spy.calledOnce, true);56 });...
Using AI Code Generation
1wpt.event_test(function(err, data) {2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8wpt.event_test(function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15wpt.event_test(function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22wpt.event_test(function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29wpt.event_test(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36wpt.event_test(function(err, data) {37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43wpt.event_test(function(err, data) {44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});50wpt.event_test(function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57wpt.event_test(function(err, data) {58 if (err) {59 console.log(err);60 } else {61 console.log(data);62 }63});64wpt.event_test(function(err, data) {65 if (err) {66 console.log(err);67 } else {68 console.log(data);69 }70});
Using AI Code Generation
1function event_test(test_name, test_function, properties) {2 test(function() {3 var event = new Event(test_name, properties);4 assert_equals(event.type, test_name);5 assert_equals(event.bubbles, properties.bubbles);6 assert_equals(event.cancelable, properties.cancelable);7 assert_equals(event.defaultPrevented, false);8 assert_equals(event.target, null);9 assert_equals(event.currentTarget, null);10 assert_equals(event.eventPhase, 0);11 test_function(event);12 }, test_name);13}14function event_test(test_name, test_function, properties) {15 test(function() {16 var event = new Event(test_name, properties);17 assert_equals(event.type, test_name);18 assert_equals(event.bubbles, properties.bubbles);19 assert_equals(event.cancelable, properties.cancelable);20 assert_equals(event.defaultPrevented, false);21 assert_equals(event.target, null);22 assert_equals(event.currentTarget, null);23 assert_equals(event.eventPhase, 0);24 test_function(event);25 }, test_name);26}27function event_test(test_name, test_function, properties) {28 test(function() {29 var event = new Event(test_name, properties);30 assert_equals(event.type, test_name);31 assert_equals(event.bubbles, properties.bubbles);32 assert_equals(event.cancelable, properties.cancelable);33 assert_equals(event.defaultPrevented, false);34 assert_equals(event.target, null);35 assert_equals(event.currentTarget, null);36 assert_equals(event.eventPhase, 0);37 test_function(event);38 }, test_name);39}40function event_test(test_name, test_function, properties) {41 test(function() {42 var event = new Event(test_name, properties);43 assert_equals(event.type, test_name);44 assert_equals(event.bubbles, properties.bubbles);45 assert_equals(event.cancelable, properties.cancelable);46 assert_equals(event.defaultPrevented, false);47 assert_equals(event.target, null);48 assert_equals(event.currentTarget, null);49 assert_equals(event.eventPhase, 0);50 test_function(event);51 }, test_name);52}
Using AI Code Generation
1var wpt = require('./wpt.js');2var assert = require('assert');3wpt.event_test(function() {4 assert(true);5});6exports.event_test = function(callback) {7 var test = new Test();8 test.run(callback);9};10var wpt = require('./wpt.js');11var assert = require('assert');12wpt.event_test(function() {13 assert(true);14});15exports.event_test = function(callback) {16 var test = new Test();17 test.run(callback);18};19var wpt = require('./wpt.js');20var assert = require('assert');21wpt.event_test(function() {22 assert(true);23});24exports.event_test = function(callback) {25 var test = new Test();26 test.run(callback);27};28var wpt = require('./wpt.js');29var assert = require('assert');30wpt.event_test(function() {31 assert(true);32});33exports.event_test = function(callback) {34 var test = new Test();35 test.run(callback);36};37var wpt = require('./wpt.js');38var assert = require('assert');39wpt.event_test(function() {40 assert(true);41});42exports.event_test = function(callback) {43 var test = new Test();44 test.run(callback);45};46var wpt = require('./wpt.js');
Using AI Code Generation
1wpt.event_test("onload", function() {2}, "Test onload event");3wpt.event_test("onunload", function() {4}, "Test onunload event");5wpt.event_test("onbeforeunload", function() {6}, "Test onbeforeunload event");7wpt.event_test("onerror", function() {8}, "Test onerror event");
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('your_key_here');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new wpt('your_key_here');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new wpt('your_key_here');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26var wpt = new wpt('your_key_here');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34var wpt = new wpt('your_key_here');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wpt = new wpt('your_key_here');43 if (err
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
Developed in 2004 by Thoughtworks for internal usage, Selenium is a widely used tool for automated testing of web applications. Initially, Selenium IDE(Integrated Development Environment) was being used by multiple organizations and testers worldwide, benefits of automation testing with Selenium saved a lot of time and effort. The major downside of automation testing with Selenium IDE was that it would only work with Firefox. To resolve the issue, Selenium RC(Remote Control) was used which enabled Selenium to support automated cross browser testing.
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
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!!