Best JavaScript code snippet using jest
index.js
Source:index.js
...247 printer248 ) +249 '}';250}251function isNewPlugin(plugin) {252 return plugin.serialize != null;253}254function printPlugin(plugin, val, config, indentation, depth, refs) {255 let printed;256 try {257 printed = isNewPlugin(plugin)258 ? plugin.serialize(val, config, indentation, depth, refs, printer)259 : plugin.print(260 val,261 valChild => printer(valChild, config, indentation, depth, refs),262 str => {263 const indentationNext = indentation + config.indent;264 return (265 indentationNext +266 str.replace(NEWLINE_REGEXP, '\n' + indentationNext)267 );268 },269 {270 edgeSpacing: config.spacingOuter,271 min: config.min,...
builder.index.entity.plugin.js
Source:builder.index.entity.plugin.js
1/*2 * Builder Index controller Plugin entity controller3 */4+function ($) { "use strict";5 if ($.oc.builder === undefined)6 $.oc.builder = {}7 if ($.oc.builder.entityControllers === undefined)8 $.oc.builder.entityControllers = {}9 var Base = $.oc.builder.entityControllers.base,10 BaseProto = Base.prototype11 var Plugin = function(indexController) {12 Base.call(this, 'plugin', indexController)13 this.popupZIndex = 5050 // This popup should be above the flyout overlay, which z-index is 500014 }15 Plugin.prototype = Object.create(BaseProto)16 Plugin.prototype.constructor = Plugin17 // PUBLIC METHODS18 // ============================19 Plugin.prototype.cmdMakePluginActive = function(ev) {20 var $target = $(ev.currentTarget),21 selectedPluginCode = $target.data('pluginCode')22 this.makePluginActive(selectedPluginCode)23 }24 Plugin.prototype.cmdCreatePlugin = function(ev) {25 var $target = $(ev.currentTarget)26 $target.one('shown.oc.popup', this.proxy(this.onPluginPopupShown))27 $target.popup({28 handler: 'onPluginLoadPopup',29 zIndex: this.popupZIndex30 })31 }32 Plugin.prototype.cmdApplyPluginSettings = function(ev) {33 var $form = $(ev.currentTarget),34 self = this35 $.oc.stripeLoadIndicator.show()36 $form.request('onPluginSave').always(37 $.oc.builder.indexController.hideStripeIndicatorProxy38 ).done(function(data){39 $form.trigger('close.oc.popup')40 self.applyPluginSettingsDone(data)41 })42 }43 Plugin.prototype.cmdEditPluginSettings = function(ev) {44 var $target = $(ev.currentTarget)45 $target.one('shown.oc.popup', this.proxy(this.onPluginPopupShown))46 $target.popup({47 handler: 'onPluginLoadPopup',48 zIndex: this.popupZIndex,49 extraData: {50 pluginCode: $target.data('pluginCode')51 }52 })53 }54 // EVENT HANDLERS55 // ============================56 Plugin.prototype.onPluginPopupShown = function(ev, button, popup) {57 $(popup).find('input[name=name]').focus()58 }59 // INTERNAL METHODS60 // ============================61 Plugin.prototype.applyPluginSettingsDone = function(data) {62 if (data.responseData !== undefined && data.responseData.isNewPlugin !== undefined) {63 this.makePluginActive(data.responseData.pluginCode, true)64 }65 }66 Plugin.prototype.makePluginActive = function(pluginCode, updatePluginList) {67 var $form = $('#builder-plugin-selector-panel form').first()68 $.oc.stripeLoadIndicator.show()69 $form.request('onPluginSetActive', {70 data: {71 pluginCode: pluginCode,72 updatePluginList: (updatePluginList ? 1 : 0)73 }74 }).always(75 $.oc.builder.indexController.hideStripeIndicatorProxy76 ).done(77 this.proxy(this.makePluginActiveDone)78 )79 }80 Plugin.prototype.makePluginActiveDone = function(data) {81 var pluginCode = data.responseData.pluginCode82 $('#builder-plugin-selector-panel [data-control=filelist]').fileList('markActive', pluginCode)83 }84 // REGISTRATION85 // ============================86 $.oc.builder.entityControllers.plugin = Plugin;...
build-options.js
Source:build-options.js
1'use strict';2const path = require('path').posix;3const _ = require('lodash');4const defaultGens = require('./default-gens');5const validateOptions = require('./validate-options');6function getAddonPublicDir(app) {7 // When SVGJar is used by an addon, the addon's public directory8 // is used as the default source of SVG images.9 return path.join(app.root, app.treePaths.public);10}11function getAppPublicDir(app) {12 // When SVGJar is used by an app, the apps's public directory13 // is used as the default source of SVG images.14 return app.options.trees.public;15}16function getPluginName(plugin) {17 return Object.keys(plugin)[0];18}19function mergeOptimizerPlugins(defaultPlugins, customPlugins) {20 let modifiedPlugins = defaultPlugins.map(defaultPlugin => {21 let pluginName = getPluginName(defaultPlugin);22 let customPlugin = customPlugins.find(23 plugin => plugin[pluginName] !== undefined24 );25 return Object.assign({}, customPlugin || defaultPlugin);26 });27 let newPlugins = customPlugins.filter(customPlugin => {28 let pluginName = getPluginName(customPlugin);29 let isNewPlugin = defaultPlugins.every(30 defaultPlugin => defaultPlugin[pluginName] === undefined31 );32 return isNewPlugin;33 });34 return [...modifiedPlugins, ...newPlugins];35}36function buildOptions(app) {37 let customOpts = app.options.svgJar || {};38 let isDevelopment = app.env === 'development';39 let isUsedByAddon = !!app.parent;40 let defaultSourceDir = isUsedByAddon41 ? getAddonPublicDir(app)42 : getAppPublicDir(app);43 let defaultOpts = {44 rootURL: '/',45 sourceDirs: [defaultSourceDir],46 strategy: 'inline',47 stripPath: true,48 optimizer: {49 plugins: [50 { removeTitle: false },51 { removeDesc: { removeAny: false } },52 { removeViewBox: false },53 ],54 },55 persist: true,56 validations: {57 throwOnFailure: false,58 validateViewBox: true,59 checkForDuplicates: true,60 },61 viewer: {62 enabled: isDevelopment && !isUsedByAddon,63 },64 inline: {65 idGen: defaultGens.inlineIdGen,66 copypastaGen: defaultGens.inlineCopypastaGen,67 },68 symbol: {69 idGen: defaultGens.symbolIdGen,70 copypastaGen: defaultGens.symbolCopypastaGen,71 outputFile: '/assets/symbols.svg',72 prefix: '',73 includeLoader: true,74 containerAttrs: {75 style: 'position: absolute; width: 0; height: 0;',76 width: '0',77 height: '0',78 version: '1.1',79 xmlns: 'http://www.w3.org/2000/svg',80 'xmlns:xlink': 'http://www.w3.org/1999/xlink',81 },82 },83 };84 validateOptions(defaultOpts, customOpts);85 let options = _.merge({}, defaultOpts, customOpts);86 options.strategy = _.castArray(options.strategy);87 if (customOpts.optimizer && customOpts.optimizer.plugins) {88 options.optimizer.plugins = mergeOptimizerPlugins(89 defaultOpts.optimizer.plugins,90 customOpts.optimizer.plugins91 );92 }93 if (customOpts.symbol && customOpts.symbol.containerAttrs) {94 options.symbol.containerAttrs = customOpts.symbol.containerAttrs;95 }96 return options;97}...
postcss-plugin-list.js
Source:postcss-plugin-list.js
1const debug = require("@swissquote/crafty-commons/packages/debug")(2 "postcss-swissquote-preset"3);4module.exports = () => {5 const listed = [];6 function reportOnPlugin(plugin) {7 if (!plugin.postcssPlugin) {8 return "- ??? unknown ???";9 }10 const isNewPlugin = listed.indexOf(plugin.postcssPlugin) > -1;11 listed.push(plugin.postcssPlugin);12 return `- ${plugin.postcssPlugin} ${isNewPlugin ? " (duplicate)" : ""}`;13 }14 return {15 postcssPlugin: "plugin-list",16 Once(root, { result }) {17 const plugins = result.processor.plugins.map(reportOnPlugin);18 debug("Used plugins:", plugins.join("\n"));19 }20 };21};...
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!!