Best JavaScript code snippet using best
winjs.polyfill.promise.test.ts
Source:winjs.polyfill.promise.test.ts
...77 });78 // run the same tests for the native and polyfill promise79 (<any[]>[Promise, PolyfillPromise]).forEach(PromiseCtor => {80 test(PromiseCtor.name + ', resolved value', function () {81 return new PromiseCtor((resolve: Function) => resolve(1)).then((value: number) => assert.equal(value, 1));82 });83 test(PromiseCtor.name + ', rejected value', function () {84 return new PromiseCtor((_: Function, reject: Function) => reject(1)).then(null, (value: number) => assert.equal(value, 1));85 });86 test(PromiseCtor.name + ', catch', function () {87 return new PromiseCtor((_: Function, reject: Function) => reject(1)).catch((value: number) => assert.equal(value, 1));88 });89 test(PromiseCtor.name + ', static-resolve', function () {90 return PromiseCtor.resolve(42).then((value: number) => assert.equal(value, 42));91 });92 test(PromiseCtor.name + ', static-reject', function () {93 return PromiseCtor.reject(42).then(null, (value: number) => assert.equal(value, 42));94 });95 test(PromiseCtor.name + ', static-all, 1', function () {96 return PromiseCtor.all([97 PromiseCtor.resolve(1),98 PromiseCtor.resolve(2)99 ]).then((values: number[]) => {100 assert.deepEqual(values, [1, 2]);101 });102 });103 test(PromiseCtor.name + ', static-all, 2', function () {104 return PromiseCtor.all([105 PromiseCtor.resolve(1),106 3,107 PromiseCtor.resolve(2)108 ]).then((values: number[]) => {109 assert.deepEqual(values, [1, 3, 2]);110 });111 });112 test(PromiseCtor.name + ', static-all, 3', function () {113 return PromiseCtor.all([114 PromiseCtor.resolve(1),115 PromiseCtor.reject(13),116 PromiseCtor.reject(12),117 ]).catch((values: number) => {118 assert.deepEqual(values, 13);119 });120 });121 test(PromiseCtor.name + ', static-race, 1', function () {122 return PromiseCtor.race([123 PromiseCtor.resolve(1),124 PromiseCtor.resolve(2),125 ]).then((value: number) => {126 assert.deepEqual(value, 1);127 });128 });129 test(PromiseCtor.name + ', static-race, 2', function () {130 return PromiseCtor.race([131 PromiseCtor.reject(-1),132 PromiseCtor.resolve(2),133 ]).catch((value: number) => {134 assert.deepEqual(value, -1);135 });136 });137 test(PromiseCtor.name + ', static-race, 3', function () {138 return PromiseCtor.race([139 PromiseCtor.resolve(1),140 PromiseCtor.reject(2),141 ]).then((value: number) => {142 assert.deepEqual(value, 1);143 });144 });145 test(PromiseCtor.name + ', throw in ctor', function () {146 return new PromiseCtor(() => {147 throw new Error('sooo bad');148 }).catch((err: Error) => {149 assert.equal(err.message, 'sooo bad');150 });151 });152 });...
mixin.ts
Source:mixin.ts
1// tslint:disable: max-classes-per-file2import { Document } from 'mongoose';3import { Model, SubDocument, Resource } from './model';4import { Ctor } from '../utils';5import * as Base from './base';6import { gtSchemaStore } from '../store/schema-store';7function mixObjects(base: any, mixins: any[]): void {8 mixins.forEach(mixin => {9 Object.getOwnPropertyNames(mixin)10 .concat(Object.getOwnPropertySymbols(mixin) as any)11 .forEach(name => {12 // mixin can't override base behavior, only add13 if (!base.hasOwnProperty(name)) {14 // if its a property descriptor we need to rewire the context15 const propDesc = Object.getOwnPropertyDescriptor(mixin, name);16 if (propDesc) {17 Object.defineProperty(base, name, propDesc);18 } else {19 base[name] = mixin[name];20 }21 }22 });23 });24}25export function GtQuery<Q1>(QH: Ctor<Q1>): <T, C>(Cls: Ctor<Document & T> & Model & C) => Ctor<Document & T> & C & Model<Q1>26export function GtQuery<Q1, Q2>(Q1: Ctor<Q1>, Q2: Ctor<Q2>): <T, C>(Cls: Ctor<Document & T> & Model & C) => Ctor<Document & T> & C & Model<Q1 & Q2>27export function GtQuery<Q1, Q2, Q3>(Q1: Ctor<Q1>, Q2: Ctor<Q2>, Q3: Ctor<Q3>): <T, C>(Cls: Ctor<Document & T> & Model & C) => Ctor<Document & T> & C & Model<Q1 & Q2 & Q3>28export function GtQuery<Q1, Q2, Q3, Q4>(Q1: Ctor<Q1>, Q2: Ctor<Q2>, Q3: Ctor<Q3>, Q4: Ctor<Q4>): <T, C>(Cls: Ctor<Document & T> & Model & C) => Ctor<Document & T> & C & Model<Q1 & Q2 & Q3 & Q4>29export function GtQuery<QMIXIN>(...mixins: Array<Ctor<QMIXIN>>): <T, C>(Cls: Ctor<Document & T> & Model & C) => Ctor<Document & T> & C & Model<QMIXIN> {30 return <T, C>(Cls: Ctor<Document & T> & Model & C) => {31 if (mixins.length > 0) {32 class QueryHelper { }33 mixObjects(QueryHelper.prototype, mixins.map(m => m.prototype));34 mixObjects(QueryHelper, mixins);35 gtSchemaStore.getCreate(Cls).defineQueryHelper(QueryHelper);36 }37 return Cls as any;38 }39}40export function GtModel(): Ctor<Document> & Model;41export function GtModel<T1, C1>(m1: C1 & Ctor<T1>): Ctor<Document & T1> & Model & C1;42export function GtModel<T1, C1, T2, C2>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>): Ctor<Document & T1 & T2> & Model & C1 & C2;43export function GtModel<T1, C1, T2, C2, T3, C3>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>): Ctor<Document & T1 & T2 & T3> & Model & C1 & C2 & C3;44export function GtModel<T1, C1, T2, C2, T3, C3, T4, C4>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>, m4: C4 & Ctor<T4>): Ctor<Document & T1 & T2 & T3 & T4> & Model & C1 & C2 & C3 & C4;45export function GtModel<T1, C1, T2, C2, T3, C3, T4, C4, T5, C5>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>, m4: C4 & Ctor<T4>, m5: C5 & Ctor<T5>): Ctor<Document & T1 & T2 & T3 & T4 & T5> & Model & C1 & C2 & C3 & C4 & C5;46export function GtModel<TMIXIN, CMIXIN>(...mixins: Array<CMIXIN & Ctor<TMIXIN>>): Ctor<TMIXIN> & CMIXIN {47 class GtModelContainer extends Base.GtModelContainer { }48 if (mixins.length > 0) {49 mixObjects(GtModelContainer.prototype, mixins.map(m => m.prototype));50 mixObjects(GtModelContainer, mixins);51 gtSchemaStore.getCreate(GtModelContainer).defineMixins(mixins);52 }53 return GtModelContainer as any;54}55export function GtResource(): Ctor<SubDocument> & Resource;56export function GtResource<T1, C1>(m1: C1 & Ctor<T1>): Ctor<SubDocument & T1> & Resource & C1;57export function GtResource<T1, C1, T2, C2>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>): Ctor<SubDocument & T1 & T2> & Resource & C1 & C2;58export function GtResource<T1, C1, T2, C2, T3, C3>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>): Ctor<SubDocument & T1 & T2 & T3> & Resource & C1 & C2 & C3;59export function GtResource<T1, C1, T2, C2, T3, C3, T4, C4>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>, m4: C4 & Ctor<T4>): Ctor<SubDocument & T1 & T2 & T3 & T4> & Resource & C1 & C2 & C3 & C4;60export function GtResource<T1, C1, T2, C2, T3, C3, T4, C4, T5, C5>(m1: C1 & Ctor<T1>, m2: C2 & Ctor<T2>, m3: C3 & Ctor<T3>, m4: C4 & Ctor<T4>, m5: C5 & Ctor<T5>): Ctor<SubDocument & T1 & T2 & T3 & T4 & T5> & Resource & C1 & C2 & C3 & C4 & C5;61export function GtResource<TMIXIN, CMIXIN>(...mixins: Array<CMIXIN & Ctor<TMIXIN>>): Ctor<TMIXIN> & CMIXIN {62 class GtResourceContainer extends Base.GtResourceContainer { }63 if (mixins.length > 0) {64 mixObjects(GtResourceContainer.prototype, mixins.map(m => m.prototype));65 mixObjects(GtResourceContainer, mixins);66 gtSchemaStore.getCreate(GtResourceContainer).defineMixins(mixins);67 }68 return GtResourceContainer as any;...
util.d.ts
Source:util.d.ts
1 declare const noop: () => void;2 declare const hasProto: boolean;3 interface VueDecorator {4 (Ctor: typeof Vue): void;5 (target: Vue, key: string): void;6 (target: Vue, key: string, index: number): void;7}8declare namespace VueClassComponent {9export function createDecorator(factory: (options: ComponentOptions<Vue>, key: string, index: number) => void): VueDecorator;10}11 //declare function mixins<A>(CtorA: VueClass<A>): VueClass<A>;12 //declare function mixins<A, B>(CtorA: VueClass<A>, CtorB: VueClass<B>): VueClass<A & B>;13 //declare function mixins<A, B, C>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>): VueClass<A & B & C>;14 //declare function mixins<A, B, C, D>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>): VueClass<A & B & C & D>;15 //declare function mixins<A, B, C, D, E>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>, CtorE: VueClass<E>): VueClass<A & B & C & D & E>;16 //declare function mixins<T>(...Ctors: VueClass<Vue>[]): VueClass<T>;17 declare function isPrimitive(value: any): boolean;18 declare function warn(message: string): void;19 interface ImixinsExtends {20 <A>(CtorA: VueClass<A>): VueClass<A>;21 <A, B>(CtorA: VueClass<A>, CtorB: VueClass<B>): VueClass<A & B>;22 <A, B, C>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>): VueClass<A & B & C>;23 <A, B, C, D>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>): VueClass<A & B & C & D>;24 <A, B, C, D, E>(CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>, CtorE: VueClass<E>): VueClass<A & B & C & D & E>;25 <T>(...Ctors: VueClass<Vue>[]): VueClass<T>;...
Using AI Code Generation
1var BestBuy = require('bestbuy');2var bestbuy = new BestBuy('your-api-key');3var BestBuy = require('bestbuy');4var bestbuy = new BestBuy('your-api-key');5var BestBuy = require('bestbuy');6var bestbuy = new BestBuy('your-api-key');7var BestBuy = require('bestbuy');8var bestbuy = new BestBuy('your-api-key');9var BestBuy = require('bestbuy');10var bestbuy = new BestBuy('your-api-key');11var BestBuy = require('bestbuy');12var bestbuy = new BestBuy('your-api-key');13var BestBuy = require('bestbuy');14var bestbuy = new BestBuy('your-api-key');15var BestBuy = require('bestbuy');16var bestbuy = new BestBuy('your-api-key');
Using AI Code Generation
1var BestBuy = require('bestbuy');2var bestbuy = new BestBuy('your-api-key');3var BestBuy = require('bestbuy');4var bestbuy = new BestBuy('your-api-key');5var BestBuy = require('bestbuy');6var bestbuy = new BestBuy('your-api-key');7var BestBuy = require('bestbuy');8var bestbuy = new BestBuy('your-api-key');9var BestBuy = require('bestbuy');10var bestbuy = new BestBuy('your-api-key');11var BestBuy = require('bestbuy');12var bestbuy = new BestBuy('your-api-key');13var BestBuy = require('bestbuy');14var bestbuy = new BestBuy('your-api-key');15var BestBuy = require('bestbuy');16var bestbuy = new BestBuy('your-api-key');
Using AI Code Generation
1var bestPractice = new BestPractice();2bestPractice.Ctor();3BestPractice.staticMethod();4BestPractice.staticMethod2();5BestPractice.staticMethod3();6BestPractice.staticMethod4();7BestPractice.staticMethod5();8BestPractice.staticMethod6();9BestPractice.staticMethod7();10BestPractice.staticMethod8();11BestPractice.staticMethod9();12BestPractice.staticMethod10();13BestPractice.staticMethod11();14BestPractice.staticMethod12();15BestPractice.staticMethod13();
Using AI Code Generation
1var bestseller = new BestSeller();2bestseller.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);3console.log("Title: " + bestseller.title);4console.log("Author: " + bestseller.author);5console.log("Year: " + bestseller.year);6console.log("Category: " + bestseller.category);7console.log("Price: " + bestseller.price);8console.log("Description: " + bestseller.description);9console.log("Isbn: " + bestseller.isbn);10console.log("Publisher: " + bestseller.publisher);11var book = new Book();12book.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);13console.log("Title: " + book.title);14console.log("Author: " + book.author);15console.log("Year: " + book.year);16var product = new Product();17product.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);18console.log("Title: " + product.title);19console.log("Author: " + product.author);20console.log("Year: " + product.year);21var item = new Item();22item.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);23console.log("Title: " + item.title);24console.log("Author: " + item.author);25console.log("Year: " + item.year);26var media = new Media();27media.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);28console.log("Title: " + media.title);29console.log("Author: " + media.author);30console.log("Year: " + media.year);31var physicalmedia = new PhysicalMedia();32physicalmedia.ctor("The Name of the Wind", "Patrick Rothfuss", 2007);33console.log("Title: " + physicalmedia.title);34console.log("Author: " + physicalmedia.author);35console.log("Year: " + physicalmdia.year);36var physicalbook = new PhysicalBook();37physicalbook.ctor("The Name of the Win", "Patrick Rothf38BestPractice.staticMethod14();39BestPractice.staticMethod15();40BestPractice.staticMethod16();41BestPractice.staticMethod17();42BestPractice.staticMethod18();43BestPractice.staticMethod19();44BestPractice.staticMethod20();45BestPractice.staticMethod21();46BestPractice.staticMethod22();47BestPractice.staticMethod23();48BestPractice.staticMethod24();49BestPractice.staticMethod25();50BestPractice.staticMethod26();
Using AI Code Generation
1var BestPractice = require('./BestPractice');2var bp = new BestPractice();3bp.Ctor();4BestPractice.Ctor()5vr BesPractic =function BestPractice() {6};7BestPractice.StticMethod = function(){8 cosole.log('BestPractice.StaticMethod()');9};10module.exports = BestPractice;11var BestPractice = requir('./BestPractice');12BestPractice.StaticMethod();13BestPractice.StaticMethod()14var BestPractice = function BestPractice() {15};16BestPractice.prototype.InstanceMethod = function() {17 console.log('BestPractice.InstanceMethod()');18};19module.exports = BestPractice;20var BestPractice = require('./BestPractice');21var bp = new BestPractice();22bp.InstanceMethod();23BestPractice.InstanceMethod()24var BestPractice = function BestPractice() {25};26BestPractice.prototype.PrivateMethod = function() {27 console.log('BestPractice.PrivateMethod()');28};29module.exports = BestPractice;30var BestPractice = require('./BestPractice');31var bp = new BestPractice();32bp.PrivateMethod();33BestPractice.PrivateMethod()34var BestPractice = function BestPractice() {35};36BestPractice.prototype.PublicMethod = function() {37 console.log('BestPractice.PublicMethod()');38};39module.exports = BestPractice;40 this.logMessage = function() {41 console.log('This is the best class ever!');42 };43}44module.exports = BestClass;45var BestClass = require('./BestClass.js');46var bestObject = new BestClass();47bestObject.logMessage();48function BestClass() {49};50BestClass.prototype.logMessage = function() {51 console.log('This is the best class ever!');52};53module.exports = BestClass;
Using AI Code Generation
1var BestPractice = require('./BestPractice');2var bp = new BestPractice();3bp.Ctor();4BestPractice.Ctor()5var BestPractice = function BestPractice() {6};7BestPractice.StaticMethod = function() {8 console.log('BestPractice.StaticMethod()');9};10module.exports = BestPractice;11var BestPractice = require('./BestPractice');12BestPractice.StaticMethod();13BestPractice.StaticMethod()14var BestPractice = function BestPractice() {15};16BestPractice.prototype.InstanceMethod = function() {17 console.log('BestPractice.InstanceMethod()');18};19module.exports = BestPractice;20var BestPractice = require('./BestPractice');21var bp = new BestPractice();22bp.InstanceMethod();23BestPractice.InstanceMethod()24var BestPractice = function BestPractice() {25};26BestPractice.prototype.PrivateMethod = function() {27 console.log('BestPractice.PrivateMethod()');28};29module.exports = BestPractice;30var BestPractice = require('./BestPractice');31var bp = new BestPractice();32bp.PrivateMethod();33BestPractice.PrivateMethod()34var BestPractice = function BestPractice() {35};36BestPractice.prototype.PublicMethod = function() {37 console.log('BestPractice.PublicMethod()');38};39module.exports = BestPractice;
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!!