Best JavaScript code snippet using jest
normalize.js
Source:normalize.js
...499 'Running all tests instead.'500 )501 );502};503function validateExtensionsToTreatAsEsm(extensionsToTreatAsEsm) {504 if (!extensionsToTreatAsEsm || extensionsToTreatAsEsm.length === 0) {505 return;506 }507 function printConfig(opts) {508 const string = opts.map(ext => `'${ext}'`).join(', ');509 return _chalk().default.bold(`extensionsToTreatAsEsm: [${string}]`);510 }511 const extensionWithoutDot = extensionsToTreatAsEsm.some(512 ext => !ext.startsWith('.')513 );514 if (extensionWithoutDot) {515 throw createConfigError(` Option: ${printConfig(516 extensionsToTreatAsEsm517 )} includes a string that does not start with a period (${_chalk().default.bold(518 '.'519 )}).520 Please change your configuration to ${printConfig(521 extensionsToTreatAsEsm.map(ext => (ext.startsWith('.') ? ext : `.${ext}`))522 )}.`);523 }524 if (extensionsToTreatAsEsm.includes('.js')) {525 throw createConfigError(526 ` Option: ${printConfig(527 extensionsToTreatAsEsm528 )} includes ${_chalk().default.bold(529 "'.js'"530 )} which is always inferred based on ${_chalk().default.bold(531 'type'532 )} in its nearest ${_chalk().default.bold('package.json')}.`533 );534 }535 if (extensionsToTreatAsEsm.includes('.cjs')) {536 throw createConfigError(537 ` Option: ${printConfig(538 extensionsToTreatAsEsm539 )} includes ${_chalk().default.bold(540 "'.cjs'"541 )} which is always treated as CommonJS.`542 );543 }544 if (extensionsToTreatAsEsm.includes('.mjs')) {545 throw createConfigError(546 ` Option: ${printConfig(547 extensionsToTreatAsEsm548 )} includes ${_chalk().default.bold(549 "'.mjs'"550 )} which is always treated as an ECMAScript Module.`551 );552 }553}554async function normalize(555 initialOptions,556 argv,557 configPath,558 projectIndex = Infinity559) {560 var _options$haste, _argv$_;561 const {hasDeprecationWarnings} = (0, _jestValidate().validate)(562 initialOptions,563 {564 comment: _utils.DOCUMENTATION_NOTE,565 deprecatedConfig: _Deprecated.default,566 exampleConfig: _ValidConfig.default,567 recursiveDenylist: [568 'collectCoverageOnlyFrom', // 'coverageThreshold' allows to use 'global' and glob strings on the same569 // level, there's currently no way we can deal with such config570 'coverageThreshold',571 'globals',572 'moduleNameMapper',573 'testEnvironmentOptions',574 'transform'575 ]576 }577 );578 let options = normalizePreprocessor(579 normalizeReporters(580 normalizeMissingOptions(581 normalizeRootDir((0, _setFromArgv.default)(initialOptions, argv)),582 configPath,583 projectIndex584 )585 )586 );587 if (options.preset) {588 options = await setupPreset(options, options.preset);589 }590 if (!options.setupFilesAfterEnv) {591 options.setupFilesAfterEnv = [];592 }593 if (594 options.setupTestFrameworkScriptFile &&595 options.setupFilesAfterEnv.length > 0596 ) {597 throw createConfigError(` Options: ${_chalk().default.bold(598 'setupTestFrameworkScriptFile'599 )} and ${_chalk().default.bold(600 'setupFilesAfterEnv'601 )} cannot be used together.602 Please change your configuration to only use ${_chalk().default.bold(603 'setupFilesAfterEnv'604 )}.`);605 }606 if (options.setupTestFrameworkScriptFile) {607 options.setupFilesAfterEnv.push(options.setupTestFrameworkScriptFile);608 }609 options.testEnvironment = (0, _jestResolve().resolveTestEnvironment)({610 requireResolveFunction: require.resolve,611 rootDir: options.rootDir,612 testEnvironment:613 options.testEnvironment ||614 require.resolve(_Defaults.default.testEnvironment)615 });616 if (!options.roots && options.testPathDirs) {617 options.roots = options.testPathDirs;618 delete options.testPathDirs;619 }620 if (!options.roots) {621 options.roots = [options.rootDir];622 }623 if (624 !options.testRunner ||625 options.testRunner === 'circus' ||626 options.testRunner === 'jest-circus'627 ) {628 options.testRunner = require.resolve('jest-circus/runner');629 } else if (options.testRunner === 'jasmine2') {630 options.testRunner = require.resolve('jest-jasmine2');631 }632 if (!options.coverageDirectory) {633 options.coverageDirectory = path().resolve(options.rootDir, 'coverage');634 }635 setupBabelJest(options); // TODO: Type this properly636 const newOptions = {..._Defaults.default};637 if (options.resolver) {638 newOptions.resolver = (0, _utils.resolve)(null, {639 filePath: options.resolver,640 key: 'resolver',641 rootDir: options.rootDir642 });643 }644 validateExtensionsToTreatAsEsm(options.extensionsToTreatAsEsm);645 if (options.watchman == null) {646 options.watchman = _Defaults.default.watchman;647 }648 const optionKeys = Object.keys(options);649 optionKeys.reduce((newOptions, key) => {650 // The resolver has been resolved separately; skip it651 if (key === 'resolver') {652 return newOptions;653 } // This is cheating, because it claims that all keys of InitialOptions are Required.654 // We only really know it's Required for oldOptions[key], not for oldOptions.someOtherKey,655 // so oldOptions[key] is the only way it should be used.656 const oldOptions = options;657 let value;658 switch (key) {...
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!!