Best JavaScript code snippet using jest
lib.js
Source:lib.js
...159 this.loadResolver = null;160 this.parentOrigin = location.protocol + "//friendfeed.com";161 window.addEventListener('message', function (event) {162 if (event.origin === self.parentOrigin && self.loadResolver !== null) {163 self.loadResolver(getSettings(event.data));164 self.loadResolver = null;165 }166 });167 },168 loadSettings: function () {169 var self = this;170 return new Promise(function (resolve) {171 self.loadResolver = resolve;172 window.parent.postMessage({action: "getSettings", value: null}, self.parentOrigin);173 });174 },175 saveSettings: function (settings) {176 var self = this;177 return new Promise(function (resolve) {...
injectorFactory.js
Source:injectorFactory.js
...45 resolveProp = function (key) {46 if (!key) {47 return;48 }49 return resolvers.loadResolver(key) || resolvers.loadResolver(50 key.displayName);51 }52 } else if (typeof resolvers === 'function') {53 resolveProp = resolvers;54 } else {55 throw new Error(56 'resolvers must be iterable or have a loadResolver function');57 }58 }59 const Injector = {60 resolveProp,61 resolver(propType, resolve) {62 if (propType == null || resolve == null) {63 throw new Error('must define both a propType and a resolver');...
tokenize-japanese.js
Source:tokenize-japanese.js
...143 };144 145 init().then(()=>{146 loaded = true;147 loadResolver();148 });...
loader-test.js
Source:loader-test.js
...20 it('should load resolvers', function () {21 const loader = loaderFactory([{22 resolvers: [a, b]23 }]);24 const r = loader.loadResolver(a);25 expect(r).to.eql(b);26 const loader2 = loaderFactory([loader]);27 loader2.addLoader({ resolvers: [[c, d]] });28 expect(loader2.loadResolver(a)).to.eql(b);29 expect(loader2.loadResolver(c)).to.eql(d);30 expect(loader2.loadResolver(e)).to.not.exist;31 expect(loader.loadResolver(c)).to.not.exist;32 });33 it('should load many resolvers', function () {34 const loader = loaderFactory([{35 resolvers: [[a, b], [c, d], [e, null]]36 }]);37 expect(loader.loadResolver(a)).to.eql(b);38 expect(loader.loadResolver(c)).to.eql(d);39 expect(loader.loadResolver(e)).to.eql(null);40 });41 it('should load mixed', function () {42 const loader = loaderFactory([{43 resolvers: [a, b]44 }]);45 const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);46 expect(loader2.loadResolver(a)).to.eql(b);47 expect(loader2.loadResolver(a)).to.eql(b);48 expect(loader2.loadResolver(c)).to.eql(d);49 expect(loader2.loadResolver(e)).to.not.exist;50 expect(loader.loadResolver(c)).to.not.exist;51 });52 it('should load list key val', function () {53 const loader = loaderFactory();54 loader.addResolver(a, b);55 const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);56 expect(loader2.listResolvers().map(v => v.name)).to.eql([c, a]);57 loader2.removeResolver(a);58 expect(loader2.listResolvers().map(v => v.name)).to.eql([c]);59 });60 it('should load list array val', function () {61 const loader = loaderFactory();62 loader.addResolver([a, b]);63 const loader2 = loaderFactory([{ resolvers: [[c, d]] }, loader]);64 expect(loader2.listResolvers().map(v => v.name)).to.eql([c, a]);65 loader2.removeResolver(a);66 expect(loader2.listResolvers().map(v => v.name)).to.eql([c]);67 });68 it('should load list nested array val', function () {69 const loader = loaderFactory();70 loader.addResolver([[a, b]]);71 expect(loader.loadResolver(a)).to.eql(b);72 });73 it('should resolve object', function () {74 const loader = loaderFactory([{75 types : {76 A77 },78 template: {79 B80 }81 }]);82 expect(loader.loadType("A")).to.eql(A);83 expect(loader.loadTemplate("B")).to.eql(B);84 });85 it('should resolve map', function () {86 const loader = loaderFactory([{87 types: new Map([['A', A], ['B', B]])88 }]);89 expect(loader.loadType("A")).to.eql(A);90 expect(loader.loadType("B")).to.eql(B);91 });92 it('should override value', function () {93 const loader = loaderFactory([{94 types: new Map([['A', 1]])95 }]);96 loader.addType('A', 2);97 loader.addLoader(loaderFactory([{98 types: {99 A: 3100 }101 }]));102 expect(loader.loadType("A")).to.eql(3);103 });104 it('should map maps', function () {105 const loader = loaderFactory();106 const propTypes = {107 a,108 b109 };110 const resolvers = {111 a: c,112 b: e113 };114 loader.addResolvers(propTypes, resolvers);115 expect(loader.loadResolver(a)).to.eql(c);116 expect(loader.loadResolver(b)).to.eql(e);117 //when mapped as such the type can be resolved via string.118 expect(loader.loadResolver('b')).to.eql(e);119 });...
app.es6
Source:app.es6
1require('angular');2require("angular-ui-router");3let _ = require("lodash");4let { Module } = require("./module");5let {AngularNamespacer} = require("./angular-namespacer");6export class App extends Module {7 constructor(name, config = {}) {8 super(name);9 this.configObject = config;10 this.routes = (state) => {};11 this.use('ui.router');12 this.widgetResolvers = [];13 }14 addWidgetResolver(resolver) {15 this.widgetResolvers.push(this.name + "." + resolver);16 }17 bootstrap(cb) {18 this.define();19 angular.element(document).ready(() => {20 angular.bootstrap(document, [this.name]);21 if(typeof cb === 'function') {22 cb();23 }24 });25 }26 define() {27 super.define();28 let loadConfig = (ConfigProvider) => {29 ConfigProvider.addAppConfig(this.configObject);30 };31 loadConfig.$inject = ["interstellar-core.ConfigProvider"];32 this.config(loadConfig);33 let loadRoutes = ($stateProvider, $urlRouterProvider) => {34 $urlRouterProvider.otherwise("/");35 this.routes($stateProvider);36 };37 loadRoutes.$inject = ["$stateProvider", "$urlRouterProvider"];38 this.config(loadRoutes);39 this._loadFunctions();40 this._loadWidgetResolvers(this.amod);41 }42 _loadWidgetResolvers(amod) {43 _.forEach(this.widgetResolvers, function (resolver) {44 let loadResolver = (resolver, WidgetResolutionService) => {45 WidgetResolutionService.addResolver(resolver);46 };47 loadResolver.$inject = [resolver, "interstellar-core.WidgetResolutionService"];48 amod.run(loadResolver);49 });50 }...
ipld-formats.js
Source:ipld-formats.js
1'use strict'2const dagPB = require('ipld-dag-pb')3const dagCBOR = require('ipld-dag-cbor')4const raw = require('ipld-raw')5const multicodec = require('multicodec')6const noop = () => {}7/**8 * @typedef {import('cids')} CID9 */10/**11 * Return an object containing supported IPLD Formats12 *13 * @param {object} [options] - IPLD options passed to the http client constructor14 * @param {Array} [options.formats] - A list of IPLD Formats to use15 * @param {Function} [options.loadFormat] - An async function that can load a format when passed a codec number16 * @returns {Function}17 */18module.exports = ({ formats = [], loadFormat = noop } = {}) => {19 formats = formats || []20 loadFormat = loadFormat || noop21 const configuredFormats = {22 [multicodec.DAG_PB]: dagPB,23 [multicodec.DAG_CBOR]: dagCBOR,24 [multicodec.RAW]: raw25 }26 formats.forEach(format => {27 configuredFormats[format.codec] = format28 })29 /**30 * Attempts to load an IPLD format for the passed CID31 *32 * @param {string} codec - The code to load the format for33 * @returns {Promise<object>} - An IPLD format34 */35 const loadResolver = async (codec) => {36 const number = multicodec.getNumber(codec)37 const format = configuredFormats[number] || await loadFormat(codec)38 if (!format) {39 throw Object.assign(40 new Error(`Missing IPLD format "${codec}"`),41 { missingMulticodec: codec }42 )43 }44 return format45 }46 return loadResolver...
schema.js
Source:schema.js
1'use strict';2var jsyaml = require('../../lib/js-yaml');3var classes = require('./classes');4module.exports = new jsyaml.Schema({5 include: [6 jsyaml.DEFAULT_FULL_SCHEMA7 ],8 explicit: [9 new jsyaml.Type('!tag3', {10 loadKind: 'mapping',11 loadResolver: classes.Tag3.fromYAMLNode,12 dumpInstanceOf: classes.Tag3,13 dumpRepresenter: classes.Tag3.toYAMLNode14 }),15 new jsyaml.Type('!tag2', {16 loadKind: 'scalar',17 loadResolver: classes.Tag2.fromYAMLNode,18 dumpInstanceOf: classes.Tag2,19 dumpRepresenter: classes.Tag2.toYAMLNode20 }),21 new jsyaml.Type('!tag1', {22 loadKind: 'mapping',23 loadResolver: classes.Tag1.fromYAMLNode,24 dumpInstanceOf: classes.Tag125 }),26 new jsyaml.Type('!foo', {27 loadKind: 'mapping',28 loadResolver: classes.Foo.fromYAMLNode,29 dumpInstanceOf: classes.Foo,30 dumpRepresenter: classes.Foo.toYAMLNode31 })32 ]...
utils.test.js
Source:utils.test.js
...6 isFunction(loadResolver)7 ).toBe(true)8 9 expect(10 isEmpty(loadResolver(path.join(__dirname, 'utils/resolvers')))11 ).toBe(false);...
LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!