Best JavaScript code snippet using fast-check-monorepo
dom.js
Source:dom.js
1/** @license MIT License (c) copyright B Cavalier & J Hann */2/**3 * dom plugin helper4 *5 * wire is part of the cujo.js family of libraries (http://cujojs.com/)6 *7 * Licensed under the MIT License at:8 * http://www.opensource.org/licenses/mit-license.php9 */10define(['wire/domReady', 'when', '../dom/base', '../object'], function(domReady, when, base, object) {11 function getElementFactory (resolver, componentDef, wire) {12 when(wire(componentDef.options), function (element) {13 if (!element || !element.nodeType || !element.tagName) {14 throw new Error('dom: non-element reference provided to element factory');15 }16 return element;17 }).then(resolver.resolve, resolver.reject);18 }19 return function createDomPlugin(options) {20 var getById, query, first, addClass, removeClass, placeAt,21 doById, doPlaceAt, resolveQuery;22 getById = options.byId || base.byId;23 query = options.query || base.querySelectorAll;24 first = options.first || base.querySelector;25 addClass = options.addClass;26 placeAt = options.placeAt || base.placeAt;27 removeClass = options.removeClass;28 function doByIdImpl(resolver, name) {29 var node;30 // if dev omitted name, they're looking for the resolver itself31 if (!name) {32 return resolver.resolve(getById);33 }34 node = getById(name);35 if (node) {36 resolver.resolve(node);37 } else {38 resolver.reject(new Error("No DOM node with id: " + name));39 }40 }41 doById = function(resolver, name /*, refObj, wire*/) {42 domReady(function() {43 doById = doByIdImpl;44 doByIdImpl(resolver, name);45 });46 };47 function doQuery(name, refObj, root, queryFunc) {48 var result, i;49 result = queryFunc(name, root);50 // if dev supplied i, try to use it51 if (typeof refObj.i != 'undefined') {52 i = refObj.i;53 if (result[i]) { // do not use `i in result` since IE gives a false positive54 return result[i];55 } else {56 throw new Error("Query '" + name + "' did not find an item at position " + i);57 }58 } else if (queryFunc == first && !result) {59 throw new Error("Query '" + name + "' did not find anything");60 } else {61 return result;62 }63 }64 function doPlaceAtImpl(resolver, facet, wire) {65 var futureRefNode, node, options, operation;66 options = facet.options;67 node = facet.target;68 // get first property and use it as the operation69 for (var p in options) {70 if (object.hasOwn(options, p)) {71 operation = p;72 break;73 }74 }75 futureRefNode = wire(makeQueryRef(options[operation]));76 when(futureRefNode, function (refNode) {77 return placeAt(node, refNode, operation);78 }).then(resolver.resolve, resolver.reject);79 }80 doPlaceAt = function(resolver, facet, wire) {81 domReady(function() {82 doPlaceAt = doPlaceAtImpl;83 doPlaceAtImpl(resolver, facet, wire);84 });85 };86 function resolveQueryImpl(resolver, name, refObj, wire, queryFunc) {87 var futureRoot;88 if (!queryFunc) {89 queryFunc = query;90 }91 // if dev omitted name, they're looking for the resolver itself92 if (!name) {93 return resolver.resolve(queryFunc);94 }95 // get string ref or object ref96 if (refObj.at && !refObj.isRoot) {97 futureRoot = wire(makeQueryRoot(refObj.at));98 }99 // sizzle will default to document if refObj.at is unspecified100 when(futureRoot, function (root) {101 return doQuery(name, refObj, root, queryFunc);102 }).then(resolver.resolve, resolver.reject);103 }104 /**105 *106 * @param resolver {Resolver} resolver to notify when the ref has been resolved107 * @param name {String} the dom query108 * @param refObj {Object} the full reference object, including options109 * @param wire {Function} wire()110 * @param [queryFunc] {Function} the function to use to query the dom111 */112 resolveQuery = function(resolver, name, refObj, wire, queryFunc) {113 domReady(function() {114 resolveQuery = resolveQueryImpl;115 resolveQueryImpl(resolver, name, refObj, wire, queryFunc);116 });117 };118 /**119 * dom.first! resolver.120 *121 * @param resolver {Resolver} resolver to notify when the ref has been resolved122 * @param name {String} the dom query123 * @param refObj {Object} the full reference object, including options124 * @param wire {Function} wire()125 */126 function resolveFirst(resolver, name, refObj, wire) {127 resolveQuery(resolver, name, refObj, wire, first);128 }129 function makeQueryRoot(ref) {130 var root = makeQueryRef(ref);131 if(root) {132 root.isRoot = true;133 }134 return root;135 }136 function makeQueryRef(ref) {137 return typeof ref == 'string' ? { $ref: ref } : ref;138 }139 function createResolver(resolverFunc, options) {140 return function(resolver, name, refObj, wire) {141 if(!refObj.at) {142 refObj.at = options.at;143 } else {144 refObj.at = makeQueryRoot(refObj.at);145 }146 return resolverFunc(resolver, name, refObj, wire);147 };148 }149 function handleClasses(node, add, remove) {150 if(add) {151 addClass(node, add);152 }153 if(remove) {154 removeClass(node, remove);155 }156 }157 /**158 * DOM plugin factory159 */160 return function(options) {161 var classes, resolvers, facets, factories, context, htmlElement;162 options.at = makeQueryRoot(options.at);163 classes = options.classes;164 context = {};165 if(classes) {166 domReady(function() {167 htmlElement = document.getElementsByTagName('html')[0];168 });169 context.initialize = function (resolver) {170 domReady(function () {171 handleClasses(htmlElement, classes.init);172 resolver.resolve();173 });174 };175 context.ready = function (resolver) {176 domReady(function () {177 handleClasses(htmlElement, classes.ready, classes.init);178 resolver.resolve();179 });180 };181 if(classes.ready) {182 context.destroy = function (resolver) {183 domReady(function () {184 handleClasses(htmlElement, null, classes.ready);185 resolver.resolve();186 });187 };188 }189 }190 factories = {191 element: getElementFactory192 };193 facets = {194 insert: {195 initialize: doPlaceAt196 }197 };198 resolvers = {};199 // id and dom are synonyms200 // dom is deprecated and for backward compat only201 resolvers.id = resolvers.dom = doById;202 if (query) {203 // dom.first is deprecated204 resolvers.first = createResolver(resolveFirst, options);205 resolvers['dom.first'] = function() {206 // TODO: Deprecation warning207 resolvers.first.apply(resolvers, arguments);208 };209 // all and query are synonyms210 resolvers.all = resolvers.query = createResolver(resolveQuery, options);211 resolvers['dom.all'] = resolvers['dom.query'] = function() {212 // TODO: Deprecation warning213 resolvers.query.apply(resolvers, arguments);214 };215 }216 return {217 context: context,218 resolvers: resolvers,219 facets: facets,220 factories: factories,221 proxies: [222 base.proxyNode223 ]224 };225 };226 };...
test_TelemetryStopwatch.js
Source:test_TelemetryStopwatch.js
1/* Any copyright is dedicated to the Public Domain.2 * http://creativecommons.org/publicdomain/zero/1.0/ */3const Cc = Components.classes;4const Ci = Components.interfaces;5const Cu = Components.utils;6const Telemetry = Cc["@mozilla.org/base/telemetry;1"]7 .getService(Ci.nsITelemetry);8let tmpScope = {};9Cu.import("resource://gre/modules/TelemetryStopwatch.jsm", tmpScope);10let TelemetryStopwatch = tmpScope.TelemetryStopwatch;11// We can't create a histogram here since the ones created with12// newHistogram are not seen by getHistogramById that the module uses.13const HIST_NAME = "TELEMETRY_PING";14const HIST_NAME2 = "RANGE_CHECKSUM_ERRORS";15let refObj = {}, refObj2 = {};16let originalCount1, originalCount2;17function run_test() {18 let histogram = Telemetry.getHistogramById(HIST_NAME);19 let snapshot = histogram.snapshot();20 originalCount1 = snapshot.counts.reduce(function (a,b) a += b);21 histogram = Telemetry.getHistogramById(HIST_NAME2);22 snapshot = histogram.snapshot();23 originalCount2 = snapshot.counts.reduce(function (a,b) a += b);24 do_check_false(TelemetryStopwatch.start(3));25 do_check_false(TelemetryStopwatch.start({}));26 do_check_false(TelemetryStopwatch.start("", 3));27 do_check_false(TelemetryStopwatch.start("", ""));28 do_check_false(TelemetryStopwatch.start({}, {}));29 do_check_true(TelemetryStopwatch.start("mark1"));30 do_check_true(TelemetryStopwatch.start("mark2"));31 do_check_true(TelemetryStopwatch.start("mark1", refObj));32 do_check_true(TelemetryStopwatch.start("mark2", refObj));33 // Same timer can't be re-started before being stopped34 do_check_false(TelemetryStopwatch.start("mark1"));35 do_check_false(TelemetryStopwatch.start("mark1", refObj));36 // Can't stop a timer that was accidentaly started twice37 do_check_false(TelemetryStopwatch.finish("mark1"));38 do_check_false(TelemetryStopwatch.finish("mark1", refObj));39 do_check_true(TelemetryStopwatch.start("NON-EXISTENT_HISTOGRAM"));40 try {41 TelemetryStopwatch.finish("NON-EXISTENT_HISTOGRAM");42 do_throw("Non-existent histogram name should throw an error.");43 } catch (e) {}44 do_check_true(TelemetryStopwatch.start("NON-EXISTENT_HISTOGRAM", refObj));45 try {46 TelemetryStopwatch.finish("NON-EXISTENT_HISTOGRAM", refObj);47 do_throw("Non-existent histogram name should throw an error.");48 } catch (e) {}49 do_check_true(TelemetryStopwatch.start(HIST_NAME));50 do_check_true(TelemetryStopwatch.start(HIST_NAME2));51 do_check_true(TelemetryStopwatch.start(HIST_NAME, refObj));52 do_check_true(TelemetryStopwatch.start(HIST_NAME2, refObj));53 do_check_true(TelemetryStopwatch.start(HIST_NAME, refObj2));54 do_check_true(TelemetryStopwatch.start(HIST_NAME2, refObj2));55 do_check_true(TelemetryStopwatch.finish(HIST_NAME));56 do_check_true(TelemetryStopwatch.finish(HIST_NAME2));57 do_check_true(TelemetryStopwatch.finish(HIST_NAME, refObj));58 do_check_true(TelemetryStopwatch.finish(HIST_NAME2, refObj));59 do_check_true(TelemetryStopwatch.finish(HIST_NAME, refObj2));60 do_check_true(TelemetryStopwatch.finish(HIST_NAME2, refObj2));61 // Verify that TS.finish deleted the timers62 do_check_false(TelemetryStopwatch.finish(HIST_NAME));63 do_check_false(TelemetryStopwatch.finish(HIST_NAME, refObj));64 // Verify that they can be used again65 do_check_true(TelemetryStopwatch.start(HIST_NAME));66 do_check_true(TelemetryStopwatch.start(HIST_NAME, refObj));67 do_check_true(TelemetryStopwatch.finish(HIST_NAME));68 do_check_true(TelemetryStopwatch.finish(HIST_NAME, refObj));69 do_check_false(TelemetryStopwatch.finish("unknown-mark")); // Unknown marker70 do_check_false(TelemetryStopwatch.finish("unknown-mark", {})); // Unknown object71 do_check_false(TelemetryStopwatch.finish(HIST_NAME, {})); // Known mark on unknown object72 // Test cancel73 do_check_true(TelemetryStopwatch.start(HIST_NAME));74 do_check_true(TelemetryStopwatch.start(HIST_NAME, refObj));75 do_check_true(TelemetryStopwatch.cancel(HIST_NAME));76 do_check_true(TelemetryStopwatch.cancel(HIST_NAME, refObj));77 // Verify that can not cancel twice78 do_check_false(TelemetryStopwatch.cancel(HIST_NAME));79 do_check_false(TelemetryStopwatch.cancel(HIST_NAME, refObj));80 // Verify that cancel removes the timers81 do_check_false(TelemetryStopwatch.finish(HIST_NAME));82 do_check_false(TelemetryStopwatch.finish(HIST_NAME, refObj));83 finishTest();84}85function finishTest() {86 let histogram = Telemetry.getHistogramById(HIST_NAME);87 let snapshot = histogram.snapshot();88 let newCount = snapshot.counts.reduce(function (a,b) a += b);89 do_check_eq(newCount - originalCount1, 5, "The correct number of histograms were added for histogram 1.");90 histogram = Telemetry.getHistogramById(HIST_NAME2);91 snapshot = histogram.snapshot();92 newCount = snapshot.counts.reduce(function (a,b) a += b);93 do_check_eq(newCount - originalCount2, 3, "The correct number of histograms were added for histogram 2.");...
Using AI Code Generation
1import { refObj } from "fast-check-monorepo";2import { refObj } from "fast-check";3import { refObj } from "fast-check-monorepo";4import { refObj } from "fast-check";5import { refObj } from "fast-check-monorepo";6import { refObj } from "fast-check";7import { refObj } from "fast-check-monorepo";8import { refObj } from "fast-check";9import { refObj } from "fast-check-monorepo";10import { refObj } from "fast-check";11import { refObj } from "fast-check-monorepo";12import { refObj } from "fast-check";13import { refObj } from "fast-check-monorepo";14import { refObj } from "fast-check";15import { refObj } from "fast-check-monorepo";16import { refObj } from "fast-check";17import { refObj } from "fast-check-monorepo";18import { refObj } from "fast-check";19import { refObj } from "fast-check-monorepo";20import { refObj } from "fast-check";21import { refObj } from "fast-check-monorepo";
Using AI Code Generation
1const { refObj } = require('fast-check-monorepo');2refObj({ a: 1, b: 2 });3const { refObj } = require('fast-check-monorepo');4refObj({ a: 1, b: 2 });5 at Object. (/home/rohit/Projects/fast-check-monorepo/test2.js:3:14)6 at Module._compile (internal/modules/cjs/loader.js:1063:30)7 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)8 at Module.load (internal/modules/cjs/loader.js:928:32)9 at Function.Module._load (internal/modules/cjs/loader.js:769:14)10 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Using AI Code Generation
1import { refObj } from 'fast-check-monorepo';2const obj = refObj({ a: 1 });3import { refObj } from 'fast-check';4const obj = refObj({ a: 1 });5import { refObj } from 'fast-check-monorepo';6const obj = refObj({ a: 1 });
Using AI Code Generation
1const refObj = require('fast-check-monorepo').refObj;2const fc = require('fast-check');3const obj = {4};5const objArb = refObj(obj);6fc.assert(7 fc.property(objArb, (o) => {8 return o.a === 1 && o.b === 2 && o.c === 3;9 })10);11const refObj = require('fast-check').refObj;12const fc = require('fast-check');13const obj = {14};15const objArb = refObj(obj);16fc.assert(17 fc.property(objArb, (o) => {18 return o.a === 1 && o.b === 2 && o.c === 3;19 })20);
Using AI Code Generation
1const refObj = require('fast-check-monorepo').refObj;2const refObj1 = refObj();3const refObj2 = refObj();4const { refObj } = require('fast-check-monorepo');5const refObj1 = refObj();6const refObj2 = refObj();7import { refObj } from 'fast-check-monorepo';8const refObj1 = refObj();9const refObj2 = refObj();10import refObj from 'fast-check-monorepo';11const refObj1 = refObj();12const refObj2 = refObj();13const refObj = require('fast-check-monorepo').default;14const refObj1 = refObj();15const refObj2 = refObj();16const refObj = require('fast-check-monorepo');17const refObj1 = refObj();18const refObj2 = refObj();19const refObj = require('fast-check-monorepo').refObj;20const refObj1 = refObj();21const refObj2 = refObj();22const { refObj } = require('fast-check-monorepo');23const refObj1 = refObj();24const refObj2 = refObj();
Using AI Code Generation
1const fc = require('fast-check');2const { refObj } = require('fast-check-monorepo');3const { refObj } = require('fast-check-monorepo');4const arb = refObj({5 name: fc.string(),6 age: fc.nat(),7});8fc.assert(9 fc.property(arb, (o) => {10 return typeof o.name === 'string' && typeof o.age === 'number';11 })12);13const fc = require('fast-check');14const { refObj } = require('fast-check-monorepo');15const arb = refObj({16 name: fc.string(),17 age: fc.nat(),18});19fc.assert(20 fc.property(arb, (o) => {21 return typeof o.name === 'string' && typeof o.age === 'number';22 })23);24const { refObj } = require('fast-check-monorepo');25const fc = require('fast-check');26const arb = refObj({27 name: fc.string(),28 age: fc.nat(),29});30fc.assert(31 fc.property(arb, (o) => {32 return typeof o.name === 'string' && typeof o.age === 'number';33 })34);35const { refObj } = require('fast-check-monorepo');36const fc = require('fast-check');37const arb = refObj({38 name: fc.string(),39 age: fc.nat(),40});41fc.assert(42 fc.property(arb, (o) => {43 return typeof o.name === 'string' && typeof o.age === 'number';44 })45);46const { refObj } = require('fast-check-monorepo');47const fc = require('fast-check');48const arb = refObj({49 name: fc.string(),50 age: fc.nat(),51});52fc.assert(53 fc.property(arb, (o) => {54 return typeof o.name === 'string' && typeof o.age === 'number';55 })56);57const { refObj } = require('fast-check-monorepo');58const fc = require('fast-check');59const arb = refObj({60 name: fc.string(),61 age: fc.nat(),62});63fc.assert(64 fc.property(arb, (o) => {65 return typeof o.name === 'string' && typeof o.age === 'number';66 })67);68const { refObj } = require('
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!!