Best JavaScript code snippet using jest
index.js
Source:index.js
...168 );169 assertLoadedBabelConfig(babelConfig, cwd, filename);170 return babelConfig;171}172function loadBabelOptions(173 cwd,174 filename,175 transformOptions,176 jestTransformOptions177) {178 const {options} = loadBabelConfig(cwd, filename, transformOptions);179 return addIstanbulInstrumentation(options, jestTransformOptions);180}181async function loadBabelOptionsAsync(182 cwd,183 filename,184 transformOptions,185 jestTransformOptions186) {187 const {options} = await loadBabelConfigAsync(cwd, filename, transformOptions);188 return addIstanbulInstrumentation(options, jestTransformOptions);189}190const createTransformer = userOptions => {191 var _inputOptions$plugins, _inputOptions$presets;192 const inputOptions =193 userOptions !== null && userOptions !== void 0 ? userOptions : {};194 const options = {195 ...inputOptions,196 caller: {197 name: 'babel-jest',198 supportsDynamicImport: false,199 supportsExportNamespaceFrom: false,200 supportsStaticESM: false,201 supportsTopLevelAwait: false,202 ...inputOptions.caller203 },204 compact: false,205 plugins:206 (_inputOptions$plugins = inputOptions.plugins) !== null &&207 _inputOptions$plugins !== void 0208 ? _inputOptions$plugins209 : [],210 presets: ((_inputOptions$presets = inputOptions.presets) !== null &&211 _inputOptions$presets !== void 0212 ? _inputOptions$presets213 : []214 ).concat(jestPresetPath),215 sourceMaps: 'both'216 };217 function mergeBabelTransformOptions(filename, transformOptions) {218 var _transformOptions$sup,219 _transformOptions$sup2,220 _transformOptions$sup3,221 _transformOptions$sup4;222 const {cwd} = transformOptions.config; // `cwd` first to allow incoming options to override it223 return {224 cwd,225 ...options,226 caller: {227 ...options.caller,228 supportsDynamicImport:229 (_transformOptions$sup = transformOptions.supportsDynamicImport) !==230 null && _transformOptions$sup !== void 0231 ? _transformOptions$sup232 : options.caller.supportsDynamicImport,233 supportsExportNamespaceFrom:234 (_transformOptions$sup2 =235 transformOptions.supportsExportNamespaceFrom) !== null &&236 _transformOptions$sup2 !== void 0237 ? _transformOptions$sup2238 : options.caller.supportsExportNamespaceFrom,239 supportsStaticESM:240 (_transformOptions$sup3 = transformOptions.supportsStaticESM) !==241 null && _transformOptions$sup3 !== void 0242 ? _transformOptions$sup3243 : options.caller.supportsStaticESM,244 supportsTopLevelAwait:245 (_transformOptions$sup4 = transformOptions.supportsTopLevelAwait) !==246 null && _transformOptions$sup4 !== void 0247 ? _transformOptions$sup4248 : options.caller.supportsTopLevelAwait249 },250 filename251 };252 }253 return {254 canInstrument: true,255 getCacheKey(sourceText, sourcePath, transformOptions) {256 const babelOptions = loadBabelConfig(257 transformOptions.config.cwd,258 sourcePath,259 mergeBabelTransformOptions(sourcePath, transformOptions)260 );261 return getCacheKeyFromConfig(262 sourceText,263 sourcePath,264 babelOptions,265 transformOptions266 );267 },268 async getCacheKeyAsync(sourceText, sourcePath, transformOptions) {269 const babelOptions = await loadBabelConfigAsync(270 transformOptions.config.cwd,271 sourcePath,272 mergeBabelTransformOptions(sourcePath, transformOptions)273 );274 return getCacheKeyFromConfig(275 sourceText,276 sourcePath,277 babelOptions,278 transformOptions279 );280 },281 process(sourceText, sourcePath, transformOptions) {282 const babelOptions = loadBabelOptions(283 transformOptions.config.cwd,284 sourcePath,285 mergeBabelTransformOptions(sourcePath, transformOptions),286 transformOptions287 );288 const transformResult = (0, _core().transformSync)(289 sourceText,290 babelOptions291 );292 if (transformResult) {293 const {code, map} = transformResult;294 if (typeof code === 'string') {295 return {296 code,...
utils.js
Source:utils.js
...39 warn(`There was an error while compiling ${filePath} ${err}`)40 }41 return content42}43const getBabelOptions = function loadBabelOptions(filename, options = {}) {44 const opts = Object.assign(options, {45 caller: {46 name: 'vue-jest',47 supportsStaticESM: false48 },49 filename,50 sourceMaps: 'both'51 })52 return loadPartialConfig(opts).options53}54const getTsJestConfig = function getTsJestConfig(config) {55 const createTransformer = require('ts-jest').createTransformer56 const tr = createTransformer()57 const configSet = tr.configsFor(config)...
babel.js
Source:babel.js
2const babel = require('@babel/core')3const debug = require('debug')('packages-scripts:utils:babel')4const {defaultSourceRoot} = require('../options')5const here = p => path.resolve(__dirname, p)6function loadBabelOptions() {7 try {8 const loadedBabelOptions = babel.loadOptions(getLoadOptions())9 debug('loaded options with `babel.loadOptions()` %o', loadedBabelOptions)10 return loadedBabelOptions11 } catch (error) {12 debug('loaded options with `babel.loadOptions()` failed')13 return null14 }15}16function loadBabelConfig() {17 let loadedBabelConfig18 try {19 loadedBabelConfig = babel.loadPartialConfig(getLoadOptions())20 } catch (error) {21 if (error.code === 'BABEL_ROOT_NOT_FOUND') {22 debug('Not found root `babel.config.js` file.')23 return null24 }25 throw error26 }27 debug(28 'loaded babel configuration derived from user-defined babel configuration file %o',29 loadedBabelConfig,30 )31 const extendConfigs = []32 if (loadedBabelConfig.config) {33 debug(`Found project-wide configuration file: ${loadedBabelConfig.config}`)34 extendConfigs.push(loadedBabelConfig.config)35 }36 if (loadedBabelConfig.babelrc) {37 debug(38 `Found sub-package-wide configuration file: ${loadedBabelConfig.babelrc}`,39 )40 extendConfigs.push(loadedBabelConfig.babelrc)41 }42 // return loadedBabelConfig43 // if (extendConfigs.length > 0) {44 // console.group('Use loaded options instead of built-in configuration')45 // console.log()46 // console.groupEnd()47 // return loadedBabelConfig.options48 // }49 if (!loadedBabelConfig.babelrc && !loadedBabelConfig.config) {50 return null51 }52 return loadedBabelConfig53}54function getLoadOptions() {55 return {56 rootMode: 'upward',57 // TODO: å¦æä¸åå¨ src çè¯åºè¯¥å¦ä½å¤ç58 filename: path.join(process.cwd(), defaultSourceRoot),59 }60}61function isUsingBuiltInBabelConfig() {62 return !loadBabelConfig()63}64function getBuiltInBabelPreset() {65 return here('../config/babel-config.js')66}67function getGeneralPluginsUsed() {68 const loadedBabelOptions = loadBabelOptions()69 if (!loadedBabelOptions) return null70 return loadedBabelOptions.plugins71}72function isPluginUsed(pluginName) {73 const usedPlugins = getGeneralPluginsUsed()74 if (!usedPlugins) return false75 return usedPlugins.some(p => p.key.includes(pluginName))76}77exports.loadBabelConfig = loadBabelConfig78exports.getBuiltInBabelPreset = getBuiltInBabelPreset79exports.isUsingBuiltInBabelConfig = isUsingBuiltInBabelConfig80exports.getGeneralBabelPluginsUsed = getGeneralPluginsUsed...
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!!