Best JavaScript code snippet using wpt
showfortests.js
Source:showfortests.js
...284 });285 it('should handle simple selectors', () => {286 expect(showFor.matchesCriteria(['fx23'])).to.beTrue();287 expect(showFor.matchesCriteria(['fx24'])).to.beTrue();288 expect(showFor.matchesCriteria(['fx25'])).to.beFalse();289 expect(showFor.matchesCriteria(['=fx23'])).to.beFalse();290 expect(showFor.matchesCriteria(['=fx24'])).to.beTrue();291 expect(showFor.matchesCriteria(['=fx25'])).to.beFalse();292 });293 it('should handle selectors with version and platform', () => {294 expect(showFor.matchesCriteria(['fx23', 'win8'])).to.beTrue();295 expect(showFor.matchesCriteria(['fx24', 'win8'])).to.beTrue();296 expect(showFor.matchesCriteria(['fx24', 'win'])).to.beTrue();297 expect(showFor.matchesCriteria(['fx24', 'linux'])).to.beFalse();298 expect(showFor.matchesCriteria(['fx25', 'win8'])).to.beFalse();299 expect(showFor.matchesCriteria(['fx25', 'win'])).to.beFalse();300 expect(showFor.matchesCriteria(['fx25', 'linux'])).to.beFalse();301 });302 it('should handle `not` with a single selector', () => {303 expect(showFor.matchesCriteria(['not fx23'])).to.beFalse();304 expect(showFor.matchesCriteria(['not fx24'])).to.beFalse();305 expect(showFor.matchesCriteria(['not fx25'])).to.beTrue();306 expect(showFor.matchesCriteria(['not =fx23'])).to.beTrue();307 expect(showFor.matchesCriteria(['not =fx24'])).to.beFalse();308 expect(showFor.matchesCriteria(['not =fx25'])).to.beTrue();309 });310 it('should handle `not` with multiple selectors', () => {311 expect(showFor.matchesCriteria(['not fx23', 'win'])).to.beFalse();312 expect(showFor.matchesCriteria(['not fx24', 'win'])).to.beFalse();313 expect(showFor.matchesCriteria(['not fx25', 'win'])).to.beTrue();314 expect(showFor.matchesCriteria(['not fx23', 'linux'])).to.beFalse();315 expect(showFor.matchesCriteria(['not fx24', 'linux'])).to.beFalse();316 expect(showFor.matchesCriteria(['not fx25', 'linux'])).to.beFalse();317 expect(showFor.matchesCriteria(['not fx23', 'not win'])).to.beFalse();318 expect(showFor.matchesCriteria(['not fx24', 'not win'])).to.beFalse();319 expect(showFor.matchesCriteria(['not fx25', 'not win'])).to.beFalse();320 expect(showFor.matchesCriteria(['not fx23', 'not linux'])).to.beFalse();321 expect(showFor.matchesCriteria(['not fx24', 'not linux'])).to.beFalse();322 expect(showFor.matchesCriteria(['not fx25', 'not linux'])).to.beTrue();323 });324 });325 describe('mixed products', () => {326 beforeEach(() => {327 showFor.state = {328 firefox: {329 enabled: true,330 platform: 'win8',331 version: {min: 24, max: 25, slug: 'fx24'}332 },333 mobile: {334 enabled: true,335 version: {min: 24, max: 25, slug: 'm24'}336 }337 };338 });339 it('should handle two products as an OR', () => {340 expect(showFor.matchesCriteria(['fx23', 'm23'])).to.beTrue();341 expect(showFor.matchesCriteria(['fx23', 'm24'])).to.beTrue();342 expect(showFor.matchesCriteria(['fx23', 'm25'])).to.beTrue();343 expect(showFor.matchesCriteria(['fx24', 'm23'])).to.beTrue();344 expect(showFor.matchesCriteria(['fx24', 'm24'])).to.beTrue();345 expect(showFor.matchesCriteria(['fx24', 'm25'])).to.beTrue();346 expect(showFor.matchesCriteria(['fx25', 'm23'])).to.beTrue();347 expect(showFor.matchesCriteria(['fx25', 'm24'])).to.beTrue();348 expect(showFor.matchesCriteria(['fx25', 'm25'])).to.beFalse();349 });350 });351 describe('disabled products', () => {352 beforeEach(() => {353 showFor.state = {354 firefox: {355 enabled: true356 },357 mobile: {358 enabled: false359 }360 };361 });362 it('should handle disabled product selectors', () => {363 expect(showFor.matchesCriteria(['fx'])).to.beTrue();364 expect(showFor.matchesCriteria(['m'])).to.beFalse();365 expect(showFor.matchesCriteria(['fx', 'm'])).to.beTrue();366 expect(showFor.matchesCriteria(['not fx'])).to.beFalse();367 expect(showFor.matchesCriteria(['not m'])).to.beTrue();368 expect(showFor.matchesCriteria(['not fx', 'm'])).to.beFalse();369 expect(showFor.matchesCriteria(['fx', 'not m'])).to.beTrue();370 expect(showFor.matchesCriteria(['not fx', 'not m'])).to.beTrue();371 });372 });373 describe('windows special cases', () => {374 beforeEach(() => {375 showFor.state = {376 firefox: {377 enabled: true,378 platform: 'win8'379 }380 };381 });382 it('should recognize `win` as all version of windows', () => {...
ChatTypes.spec.ts
Source:ChatTypes.spec.ts
1/* eslint-disable max-len */2/* eslint-disable no-constant-condition */3import chai, { expect } from 'chai';4import * as fs from 'fs';5import chaiLike from 'chai-like';6import {7 TelegramChat,8} from '../src';9chai.use(chaiLike);10const BotJSON = fs.readFileSync('./tests/data/bot.json', { encoding: 'utf8', flag: 'r' });11const PersonalJSON = fs.readFileSync('./tests/data/personal.json', { encoding: 'utf8', flag: 'r' });12const PrivateChannelJSON = fs.readFileSync('./tests/data/private_channel.json', { encoding: 'utf8', flag: 'r' });13const PrivateGroupJSON = fs.readFileSync('./tests/data/private_group.json', { encoding: 'utf8', flag: 'r' });14const PublicChannelJSON = fs.readFileSync('./tests/data/public_channel.json', { encoding: 'utf8', flag: 'r' });15const PublicSupergroupJSON = fs.readFileSync('./tests/data/public_supergroup.json', { encoding: 'utf8', flag: 'r' });16const SavedJSON = fs.readFileSync('./tests/data/saved.json', { encoding: 'utf8', flag: 'r' });17// NOTE: These tests loop through the list of available type methods to ensure consistency18// However, that means failures don't report properly. If a test fails, it can be checked in reported loop with:19// console.log('tg[typeToCheck as keyof TelegramChat]', typeToCheck, tg[typeToCheck as keyof TelegramChat]);20describe('ChatTypes', () => {21 const typeCheckMethods = [22 'isBot',23 'isSaved',24 'isPrivate',25 'isPersonal',26 'isGroup',27 'isPrivateGroup',28 'isPublicSupergroup',29 'isPrivateChannel',30 'isPublicChannel',31 'isPublic',32 ];33 describe('when bot chat json is imported', () => {34 const tg = new TelegramChat(BotJSON);35 it('only isBot and isPrivate should be true', () => {36 const beTrue = ['isBot', 'isPrivate'];37 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));38 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);39 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);40 });41 });42 describe('when personal chat json is imported', () => {43 const tg = new TelegramChat(PersonalJSON);44 it('only isPersonal and isPrivate should be true', () => {45 const beTrue = ['isPersonal', 'isPrivate'];46 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));47 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);48 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);49 });50 });51 describe('when private channel json is imported', () => {52 const tg = new TelegramChat(PrivateChannelJSON);53 it('only isPrivateChannel, isChannel, and isPrivate should be true', () => {54 const beTrue = ['isPrivateChannel', 'isPrivate', 'isChannel'];55 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));56 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);57 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);58 });59 });60 describe('when private group json is imported', () => {61 const tg = new TelegramChat(PrivateGroupJSON);62 it('only isPrivateGroup, isPrivate, and isGroup should be true', () => {63 const beTrue = ['isPrivateGroup', 'isPrivate', 'isGroup'];64 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));65 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);66 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);67 });68 });69 describe('when public channel json is imported', () => {70 const tg = new TelegramChat(PublicChannelJSON);71 it('only isPublicChannel, isChannel, and isPublic should be true', () => {72 const beTrue = ['isPublicChannel', 'isChannel', 'isPublic'];73 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));74 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);75 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);76 });77 });78 describe('when public supergroup json is imported', () => {79 const tg = new TelegramChat(PublicSupergroupJSON);80 it('only isPublicSupergroup, isGroup, and isPublic should be true', () => {81 const beTrue = ['isPublicSupergroup', 'isGroup', 'isPublic'];82 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));83 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);84 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);85 });86 });87 describe('when saved chat json is imported', () => {88 const tg = new TelegramChat(SavedJSON);89 it('only isPrivate and isSaved should be true', () => {90 const beTrue = ['isPrivate', 'isSaved'];91 const beFalse = typeCheckMethods.filter((t) => !beTrue.includes(t));92 beTrue.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.true);93 beFalse.forEach((typeToCheck) => expect(tg[typeToCheck as keyof TelegramChat]).to.be.false);94 });95 });...
arg.js
Source:arg.js
1arg=function(G){2 return function(Q, doThis){3 $l(Q)4 Q = Q.split('/');5 $l(Q)6 if(Q[1]){ mop = Q.shift()||'ex' } //;return op;7 $l(mop); $l(Q)8 if(isNum(Q)){9 pass = numPass(Q, G)}10 else {11 Q=hop(Q[0]); Q=haveFun(Q)12 rel=REL(G,Q); pair = makePair(G,Q)13 var o = yesNo (pair);14 ops={15 x: o(every)(yes) && rel.same,16 xf: o(every)(no) && rel.same,17 z: o(some)(no),18 // one:a,19 // oneWrong:,20 // oneMissing:,21 s: o(every)(yes) && rel.notLess,22 m: o(every)(yes) && rel.more,23 nm: o(every)(yes) && rel.notMore }24 //return ops25 mop = mop|| 'x';26 pass = ops [mop]27 }28 if( pass ){ $l('p'); doThis() }29 else{ $l( 'f' )}30 }}31args2=function(ag){return function(spec, op, tD){32 if(!tD){ tD=op; op='pass'}33 var pairUp = function(a,b){return filter(map(zip(a,b),compact),function(a){if(_z(a)>1){return true}})},34 hydrate=function(a){return map(p0(a),function(a){if(iUp(a)){return not($w[tUp(a)])}return $w[tUp(a)]})},35 makeTest=function(a,s){return pairUp(a, hydrate(s))},36 ARGS = _z(ag), SPECS = _z(spec),more = ARGS > SPECS,less = ARGS < SPECS,theSame = ARGS == SPECS,37 notLess = ARGS >= SPECS,notMore = ARGS <= SPECS,different=!theSame,nada=ARGS== 0,38 o=function(fl, it){return bool(fl(makeTest(ag, spec), it))},39 OPS={40 pass: o(all, beTrue).and(theSame)(),41 orLess: o(all,beTrue).and(notMore)(),42 orMore: o(all, beTrue).and(notLess)(),43 noFail: o(all, beTrue)(),44 somePass: o(some, beTrue)(),45 nonePass: o(all, beFalse)(),46 someFail: o(some, beFalse)(),47 fail: o(some, beFalse).or(different)(),48 antiPass: o(all, beFalse).and(theSame)(),49 mix: o(some, beTrue).and( o(some,beFalse)())()}...
Using AI Code Generation
1wpt.assert.beFalse(false);2wpt.assert.beTrue(true);3wpt.assert.beEqual(1,1);4wpt.assert.beNotEqual(1,2);5wpt.assert.beNull(null);6wpt.assert.beNotNull(1);7wpt.assert.beUndefined(undefined);8wpt.assert.beNotUndefined(1);9wpt.assert.beNaN(NaN);10wpt.assert.beNotNaN(1);11wpt.assert.beEmpty("");12wpt.assert.beNotEmpty("1");13wpt.assert.beArray([]);14wpt.assert.beNotArray(1);15wpt.assert.beObject({});16wpt.assert.beNotObject(1);17wpt.assert.beType("string", "1");18wpt.assert.beNotType("string", 1);19wpt.assert.beInstanceOf("string", "1");20wpt.assert.beNotInstanceOf("string", 1);21wpt.assert.beLessThan(1,2);22wpt.assert.beGreaterThan(2,1);23wpt.assert.beLessOrEqualThan(1,2);
Using AI Code Generation
1var wpt = require('wpt');2var wpt = require('wpt');3var wpt = require('wpt');4var wpt = require('wpt');5var wpt = require('wpt');6var wpt = require('wpt');7var wpt = require('wpt');8var wpt = require('wpt');9var wpt = require('wpt');10var wpt = require('wpt');
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.expect(false).to.beFalse();3var chai = require('chai');4chai.expect(false).to.be.false;5var assert = require('assert');6assert.equal(false,false);7var wptoolkit = require('wptoolkit');8wptoolkit.expect(true).to.beTrue();9var chai = require('chai');10chai.expect(true).to.be.true;11var assert = require('assert');12assert.equal(true,true);13var wptoolkit = require('wptoolkit');14wptoolkit.expect(2).to.beGreaterThan(1);15var chai = require('chai');16chai.expect(2).to.be.greaterThan(1);17var assert = require('assert');18assert.equal(2>1,true);19var wptoolkit = require('wptoolkit');20wptoolkit.expect(2).to.beLessThan(3);21var chai = require('chai');22chai.expect(2).to.be.lessThan(3);23var assert = require('assert');24assert.equal(2<3,true);25var wptoolkit = require('wptoolkit');26wptoolkit.expect(2).to.beGreaterThanOrEqual(2);27var chai = require('chai');28chai.expect(2).to.be.greaterThanOrEqual(2);29var assert = require('assert');30assert.equal(2>=2,true);
Using AI Code Generation
1var wpt = require('wpt');2var should = require('should');3var assert = require('assert');4var chai = require('chai');5var expect = chai.expect;6var chaiAsPromised = require('chai-as-promised');7chai.use(chaiAsPromised);8var wpt = require('wpt');9var WPT = new wpt('<your wpt key>');10var options = {11};12describe('test', function () {13 it('should return false', function () {14 return WPT.runTest(url, options).then(function (data) {15 expect(false).to.be.false;16 });17 });18});19var wpt = require('wpt');20var should = require('should');21var assert = require('assert');22var chai = require('chai');23var expect = chai.expect;24var chaiAsPromised = require('chai-as-promised');25chai.use(chaiAsPromised);26var wpt = require('wpt');27var WPT = new wpt('<your wpt key>');28var options = {29};30describe('test', function () {31 it('should return true', function () {32 return WPT.runTest(url, options).then(function (data) {33 expect(true).to.be.true;34 });35 });36});37var wpt = require('wpt');38var should = require('should');39var assert = require('assert');40var chai = require('chai');41var expect = chai.expect;42var chaiAsPromised = require('chai-as-promised');43chai.use(chaiAsPromised);44var wpt = require('wpt');45var WPT = new wpt('<your wpt key>');46var options = {
Using AI Code Generation
1var wpt = require('wpt');2var should = require('should');3wpt.beFalse(false);4wpt.beFalse(true).should.throw();5var wpt = require('wpt');6var should = require('should');7wpt.beTrue(true);8wpt.beTrue(false).should.throw();9var wpt = require('wpt');10var should = require('should');11wpt.equal(1,1);12wpt.equal(1,2).should.throw();13var wpt = require('wpt');14var should = require('should');15wpt.notEqual(1,2);16wpt.notEqual(1,1).should.throw();17var wpt = require('wpt');18var should = require('should');19wpt.beUndefined(undefined);20wpt.beUndefined(null).should.throw();21var wpt = require('wpt');22var should = require('should');23wpt.notBeUndefined(null);24wpt.notBeUndefined(undefined).should.throw();25var wpt = require('wpt');26var should = require('should');27wpt.beNull(null);28wpt.beNull(undefined).should.throw();29var wpt = require('wpt');30var should = require('should');31wpt.notBeNull(undefined);32wpt.notBeNull(null).should.throw();33var wpt = require('wpt');34var should = require('should');35wpt.beEmpty('');36wpt.beEmpty(' ').should.throw();37var wpt = require('wpt');38var should = require('should');39wpt.notBeEmpty(' ');40wpt.notBeEmpty('').should.throw();
Using AI Code Generation
1var wpt = require('wpt');2var assert = require('assert');3wpt.beFalse(false);4wpt.beFalse(true);5var wpt = require('wpt');6var assert = require('assert');7wpt.beTrue(true);8wpt.beTrue(false);9var wpt = require('wpt');10var assert = require('assert');11wpt.beUndefined();12wpt.beUndefined(null);13var wpt = require('wpt');14var assert = require('assert');15wpt.beNull(null);16wpt.beNull(undefined);17var wpt = require('wpt');18var assert = require('assert');19wpt.beEmpty('');20wpt.beEmpty('test');21var wpt = require('wpt');22var assert = require('assert');23wpt.haveLength('test', 4);24wpt.haveLength('test', 3);25var wpt = require('wpt');26var assert = require('assert');27wpt.beLessThan(2, 3);28wpt.beLessThan(3, 2);29var wpt = require('wpt');30var assert = require('assert');31wpt.beGreaterThan(3, 2);32wpt.beGreaterThan(2, 3);33var wpt = require('wpt');34var assert = require('assert');35wpt.beLessThanOrEqualTo(2, 2);36wpt.beLessThanOrEqualTo(3, 2
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!!