How to use runGlobalHook method in Jest

Best JavaScript code snippet using jest

index.js

Source:index.js Github

copy

Full Screen

...146 Logger.log(`${Logger.colors.green('→')} Completed [${hookName}].`);147 return result;148 });149 }150 runGlobalHook(hookName) {151 if (!this.globalHooks[hookName]) {152 return Promise.resolve();153 }154 return this.handleRunnable(hookName, () => {155 return this.globalHooks[hookName].run(this.client);156 });157 }158 createSession() {159 if (this.client.sessionId || this.context.unitTestsMode) {160 return Promise.resolve();161 }162 return this.client.createSession(this.argv);163 }164 /**165 * Runs the test suite, including all hooks166 */167 runTestSuite() {168 return this.createSession()169 .catch(err => {170 err.sessionCreate = true;171 this.reporter.registerTestError(err);172 throw err;173 })174 .then(data => {175 this.setReportPrefix(data);176 return this.runGlobalHook('beforeEach');177 })178 .then(() => this.runHook('before'))179 .then(result => {180 if (result instanceof Error) {181 Logger.error(result);182 }183 return this.runNextTestCase();184 })185 .catch(err => {186 if (err.sessionCreate) {187 throw err;188 }189 if (!isAssertionError(err)) {190 Logger.error(err);191 }192 // testcase failed - this catch ensures that the after hook is being called193 return err;194 })195 .then(_ => this.runHook('after'))196 .catch(err => {197 if (err.code === 'ECONNREFUSED') {198 throw err;199 }200 if (!err.sessionCreate) {201 Logger.error(err);202 }203 // testsuite failed - this catch ensures that the global afterEach will always run204 return this.terminate('FAILED');205 })206 .then(_ => this.runGlobalHook('afterEach'))207 .catch(err => {208 if (err.sessionCreate) {209 throw err;210 }211 Logger.error(err);212 // catching errors thrown inside the global afterEach213 return true;214 })215 .then(failures => {216 if (this.shouldRetrySuite()) {217 return this.retrySuite();218 }219 return failures;220 })...

Full Screen

Full Screen

jest-cli_vx.x.x.js

Source:jest-cli_vx.x.x.js Github

copy

Full Screen

1// flow-typed signature: c54c443d1fcfb03f0e9d849770c079912// flow-typed version: <<STUB>>/jest-cli_v^24.1.0/flow_v0.92.13/**4 * This is an autogenerated libdef stub for:5 *6 * 'jest-cli'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'jest-cli' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'jest-cli/bin/jest' {23 declare module.exports: any;24}25declare module 'jest-cli/build/cli/args' {26 declare module.exports: any;27}28declare module 'jest-cli/build/cli/index' {29 declare module.exports: any;30}31declare module 'jest-cli/build/collectHandles' {32 declare module.exports: any;33}34declare module 'jest-cli/build/constants' {35 declare module.exports: any;36}37declare module 'jest-cli/build/FailedTestsCache' {38 declare module.exports: any;39}40declare module 'jest-cli/build/generateEmptyCoverage' {41 declare module.exports: any;42}43declare module 'jest-cli/build/getChangedFilesPromise' {44 declare module.exports: any;45}46declare module 'jest-cli/build/getNoTestFound' {47 declare module.exports: any;48}49declare module 'jest-cli/build/getNoTestFoundFailed' {50 declare module.exports: any;51}52declare module 'jest-cli/build/getNoTestFoundRelatedToChangedFiles' {53 declare module.exports: any;54}55declare module 'jest-cli/build/getNoTestFoundVerbose' {56 declare module.exports: any;57}58declare module 'jest-cli/build/getNoTestsFoundMessage' {59 declare module.exports: any;60}61declare module 'jest-cli/build/jest' {62 declare module.exports: any;63}64declare module 'jest-cli/build/lib/active_filters_message' {65 declare module.exports: any;66}67declare module 'jest-cli/build/lib/create_context' {68 declare module.exports: any;69}70declare module 'jest-cli/build/lib/handle_deprecation_warnings' {71 declare module.exports: any;72}73declare module 'jest-cli/build/lib/init/errors' {74 declare module.exports: any;75}76declare module 'jest-cli/build/lib/init/generate_config_file' {77 declare module.exports: any;78}79declare module 'jest-cli/build/lib/init/index' {80 declare module.exports: any;81}82declare module 'jest-cli/build/lib/init/modify_package_json' {83 declare module.exports: any;84}85declare module 'jest-cli/build/lib/init/questions' {86 declare module.exports: any;87}88declare module 'jest-cli/build/lib/is_valid_path' {89 declare module.exports: any;90}91declare module 'jest-cli/build/lib/log_debug_messages' {92 declare module.exports: any;93}94declare module 'jest-cli/build/lib/update_global_config' {95 declare module.exports: any;96}97declare module 'jest-cli/build/lib/watch_plugins_helpers' {98 declare module.exports: any;99}100declare module 'jest-cli/build/plugins/quit' {101 declare module.exports: any;102}103declare module 'jest-cli/build/plugins/test_name_pattern' {104 declare module.exports: any;105}106declare module 'jest-cli/build/plugins/test_path_pattern' {107 declare module.exports: any;108}109declare module 'jest-cli/build/plugins/update_snapshots_interactive' {110 declare module.exports: any;111}112declare module 'jest-cli/build/plugins/update_snapshots' {113 declare module.exports: any;114}115declare module 'jest-cli/build/pluralize' {116 declare module.exports: any;117}118declare module 'jest-cli/build/preRunMessage' {119 declare module.exports: any;120}121declare module 'jest-cli/build/ReporterDispatcher' {122 declare module.exports: any;123}124declare module 'jest-cli/build/reporters/base_reporter' {125 declare module.exports: any;126}127declare module 'jest-cli/build/reporters/coverage_reporter' {128 declare module.exports: any;129}130declare module 'jest-cli/build/reporters/coverage_worker' {131 declare module.exports: any;132}133declare module 'jest-cli/build/reporters/default_reporter' {134 declare module.exports: any;135}136declare module 'jest-cli/build/reporters/get_result_header' {137 declare module.exports: any;138}139declare module 'jest-cli/build/reporters/get_snapshot_status' {140 declare module.exports: any;141}142declare module 'jest-cli/build/reporters/get_snapshot_summary' {143 declare module.exports: any;144}145declare module 'jest-cli/build/reporters/notify_reporter' {146 declare module.exports: any;147}148declare module 'jest-cli/build/reporters/Status' {149 declare module.exports: any;150}151declare module 'jest-cli/build/reporters/summary_reporter' {152 declare module.exports: any;153}154declare module 'jest-cli/build/reporters/utils' {155 declare module.exports: any;156}157declare module 'jest-cli/build/reporters/verbose_reporter' {158 declare module.exports: any;159}160declare module 'jest-cli/build/runGlobalHook' {161 declare module.exports: any;162}163declare module 'jest-cli/build/runJest' {164 declare module.exports: any;165}166declare module 'jest-cli/build/SearchSource' {167 declare module.exports: any;168}169declare module 'jest-cli/build/SnapshotInteractiveMode' {170 declare module.exports: any;171}172declare module 'jest-cli/build/TestNamePatternPrompt' {173 declare module.exports: any;174}175declare module 'jest-cli/build/TestPathPatternPrompt' {176 declare module.exports: any;177}178declare module 'jest-cli/build/testPathPatternToRegexp' {179 declare module.exports: any;180}181declare module 'jest-cli/build/testResultHelpers' {182 declare module.exports: any;183}184declare module 'jest-cli/build/TestScheduler' {185 declare module.exports: any;186}187declare module 'jest-cli/build/testSchedulerHelper' {188 declare module.exports: any;189}190declare module 'jest-cli/build/TestSequencer' {191 declare module.exports: any;192}193declare module 'jest-cli/build/TestWatcher' {194 declare module.exports: any;195}196declare module 'jest-cli/build/types' {197 declare module.exports: any;198}199declare module 'jest-cli/build/version' {200 declare module.exports: any;201}202declare module 'jest-cli/build/watch' {203 declare module.exports: any;204}205// Filename aliases206declare module 'jest-cli/bin/jest.js' {207 declare module.exports: $Exports<'jest-cli/bin/jest'>;208}209declare module 'jest-cli/build/cli/args.js' {210 declare module.exports: $Exports<'jest-cli/build/cli/args'>;211}212declare module 'jest-cli/build/cli/index.js' {213 declare module.exports: $Exports<'jest-cli/build/cli/index'>;214}215declare module 'jest-cli/build/collectHandles.js' {216 declare module.exports: $Exports<'jest-cli/build/collectHandles'>;217}218declare module 'jest-cli/build/constants.js' {219 declare module.exports: $Exports<'jest-cli/build/constants'>;220}221declare module 'jest-cli/build/FailedTestsCache.js' {222 declare module.exports: $Exports<'jest-cli/build/FailedTestsCache'>;223}224declare module 'jest-cli/build/generateEmptyCoverage.js' {225 declare module.exports: $Exports<'jest-cli/build/generateEmptyCoverage'>;226}227declare module 'jest-cli/build/getChangedFilesPromise.js' {228 declare module.exports: $Exports<'jest-cli/build/getChangedFilesPromise'>;229}230declare module 'jest-cli/build/getNoTestFound.js' {231 declare module.exports: $Exports<'jest-cli/build/getNoTestFound'>;232}233declare module 'jest-cli/build/getNoTestFoundFailed.js' {234 declare module.exports: $Exports<'jest-cli/build/getNoTestFoundFailed'>;235}236declare module 'jest-cli/build/getNoTestFoundRelatedToChangedFiles.js' {237 declare module.exports: $Exports<'jest-cli/build/getNoTestFoundRelatedToChangedFiles'>;238}239declare module 'jest-cli/build/getNoTestFoundVerbose.js' {240 declare module.exports: $Exports<'jest-cli/build/getNoTestFoundVerbose'>;241}242declare module 'jest-cli/build/getNoTestsFoundMessage.js' {243 declare module.exports: $Exports<'jest-cli/build/getNoTestsFoundMessage'>;244}245declare module 'jest-cli/build/jest.js' {246 declare module.exports: $Exports<'jest-cli/build/jest'>;247}248declare module 'jest-cli/build/lib/active_filters_message.js' {249 declare module.exports: $Exports<'jest-cli/build/lib/active_filters_message'>;250}251declare module 'jest-cli/build/lib/create_context.js' {252 declare module.exports: $Exports<'jest-cli/build/lib/create_context'>;253}254declare module 'jest-cli/build/lib/handle_deprecation_warnings.js' {255 declare module.exports: $Exports<'jest-cli/build/lib/handle_deprecation_warnings'>;256}257declare module 'jest-cli/build/lib/init/errors.js' {258 declare module.exports: $Exports<'jest-cli/build/lib/init/errors'>;259}260declare module 'jest-cli/build/lib/init/generate_config_file.js' {261 declare module.exports: $Exports<'jest-cli/build/lib/init/generate_config_file'>;262}263declare module 'jest-cli/build/lib/init/index.js' {264 declare module.exports: $Exports<'jest-cli/build/lib/init/index'>;265}266declare module 'jest-cli/build/lib/init/modify_package_json.js' {267 declare module.exports: $Exports<'jest-cli/build/lib/init/modify_package_json'>;268}269declare module 'jest-cli/build/lib/init/questions.js' {270 declare module.exports: $Exports<'jest-cli/build/lib/init/questions'>;271}272declare module 'jest-cli/build/lib/is_valid_path.js' {273 declare module.exports: $Exports<'jest-cli/build/lib/is_valid_path'>;274}275declare module 'jest-cli/build/lib/log_debug_messages.js' {276 declare module.exports: $Exports<'jest-cli/build/lib/log_debug_messages'>;277}278declare module 'jest-cli/build/lib/update_global_config.js' {279 declare module.exports: $Exports<'jest-cli/build/lib/update_global_config'>;280}281declare module 'jest-cli/build/lib/watch_plugins_helpers.js' {282 declare module.exports: $Exports<'jest-cli/build/lib/watch_plugins_helpers'>;283}284declare module 'jest-cli/build/plugins/quit.js' {285 declare module.exports: $Exports<'jest-cli/build/plugins/quit'>;286}287declare module 'jest-cli/build/plugins/test_name_pattern.js' {288 declare module.exports: $Exports<'jest-cli/build/plugins/test_name_pattern'>;289}290declare module 'jest-cli/build/plugins/test_path_pattern.js' {291 declare module.exports: $Exports<'jest-cli/build/plugins/test_path_pattern'>;292}293declare module 'jest-cli/build/plugins/update_snapshots_interactive.js' {294 declare module.exports: $Exports<'jest-cli/build/plugins/update_snapshots_interactive'>;295}296declare module 'jest-cli/build/plugins/update_snapshots.js' {297 declare module.exports: $Exports<'jest-cli/build/plugins/update_snapshots'>;298}299declare module 'jest-cli/build/pluralize.js' {300 declare module.exports: $Exports<'jest-cli/build/pluralize'>;301}302declare module 'jest-cli/build/preRunMessage.js' {303 declare module.exports: $Exports<'jest-cli/build/preRunMessage'>;304}305declare module 'jest-cli/build/ReporterDispatcher.js' {306 declare module.exports: $Exports<'jest-cli/build/ReporterDispatcher'>;307}308declare module 'jest-cli/build/reporters/base_reporter.js' {309 declare module.exports: $Exports<'jest-cli/build/reporters/base_reporter'>;310}311declare module 'jest-cli/build/reporters/coverage_reporter.js' {312 declare module.exports: $Exports<'jest-cli/build/reporters/coverage_reporter'>;313}314declare module 'jest-cli/build/reporters/coverage_worker.js' {315 declare module.exports: $Exports<'jest-cli/build/reporters/coverage_worker'>;316}317declare module 'jest-cli/build/reporters/default_reporter.js' {318 declare module.exports: $Exports<'jest-cli/build/reporters/default_reporter'>;319}320declare module 'jest-cli/build/reporters/get_result_header.js' {321 declare module.exports: $Exports<'jest-cli/build/reporters/get_result_header'>;322}323declare module 'jest-cli/build/reporters/get_snapshot_status.js' {324 declare module.exports: $Exports<'jest-cli/build/reporters/get_snapshot_status'>;325}326declare module 'jest-cli/build/reporters/get_snapshot_summary.js' {327 declare module.exports: $Exports<'jest-cli/build/reporters/get_snapshot_summary'>;328}329declare module 'jest-cli/build/reporters/notify_reporter.js' {330 declare module.exports: $Exports<'jest-cli/build/reporters/notify_reporter'>;331}332declare module 'jest-cli/build/reporters/Status.js' {333 declare module.exports: $Exports<'jest-cli/build/reporters/Status'>;334}335declare module 'jest-cli/build/reporters/summary_reporter.js' {336 declare module.exports: $Exports<'jest-cli/build/reporters/summary_reporter'>;337}338declare module 'jest-cli/build/reporters/utils.js' {339 declare module.exports: $Exports<'jest-cli/build/reporters/utils'>;340}341declare module 'jest-cli/build/reporters/verbose_reporter.js' {342 declare module.exports: $Exports<'jest-cli/build/reporters/verbose_reporter'>;343}344declare module 'jest-cli/build/runGlobalHook.js' {345 declare module.exports: $Exports<'jest-cli/build/runGlobalHook'>;346}347declare module 'jest-cli/build/runJest.js' {348 declare module.exports: $Exports<'jest-cli/build/runJest'>;349}350declare module 'jest-cli/build/SearchSource.js' {351 declare module.exports: $Exports<'jest-cli/build/SearchSource'>;352}353declare module 'jest-cli/build/SnapshotInteractiveMode.js' {354 declare module.exports: $Exports<'jest-cli/build/SnapshotInteractiveMode'>;355}356declare module 'jest-cli/build/TestNamePatternPrompt.js' {357 declare module.exports: $Exports<'jest-cli/build/TestNamePatternPrompt'>;358}359declare module 'jest-cli/build/TestPathPatternPrompt.js' {360 declare module.exports: $Exports<'jest-cli/build/TestPathPatternPrompt'>;361}362declare module 'jest-cli/build/testPathPatternToRegexp.js' {363 declare module.exports: $Exports<'jest-cli/build/testPathPatternToRegexp'>;364}365declare module 'jest-cli/build/testResultHelpers.js' {366 declare module.exports: $Exports<'jest-cli/build/testResultHelpers'>;367}368declare module 'jest-cli/build/TestScheduler.js' {369 declare module.exports: $Exports<'jest-cli/build/TestScheduler'>;370}371declare module 'jest-cli/build/testSchedulerHelper.js' {372 declare module.exports: $Exports<'jest-cli/build/testSchedulerHelper'>;373}374declare module 'jest-cli/build/TestSequencer.js' {375 declare module.exports: $Exports<'jest-cli/build/TestSequencer'>;376}377declare module 'jest-cli/build/TestWatcher.js' {378 declare module.exports: $Exports<'jest-cli/build/TestWatcher'>;379}380declare module 'jest-cli/build/types.js' {381 declare module.exports: $Exports<'jest-cli/build/types'>;382}383declare module 'jest-cli/build/version.js' {384 declare module.exports: $Exports<'jest-cli/build/version'>;385}386declare module 'jest-cli/build/watch.js' {387 declare module.exports: $Exports<'jest-cli/build/watch'>;...

Full Screen

Full Screen

testsuite.js

Source:testsuite.js Github

copy

Full Screen

...131 Logger.log(`${Logger.colors.green('→')} Completed [${hookName}].`);132 return result;133 });134 }135 runGlobalHook(hookName) {136 if (!this.globalHooks[hookName]) {137 return Promise.resolve();138 }139 return this.handleRunnable(hookName, () => {140 return this.globalHooks[hookName].run(this.api);141 });142 }143 createSession() {144 if (this.client.sessionId || this.context.unitTestsMode) {145 return Promise.resolve();146 }147 return this.client.createSession();148 }149 /**150 * Runs the test suite, including all hooks151 */152 runTestSuite() {153 return this.createSession()154 .catch(err => {155 err.sessionCreate = true;156 this.reporter.registerTestError(err);157 throw err;158 })159 .then(data => {160 this.setReportPrefix(data);161 return this.runGlobalHook('beforeEach');162 })163 .then(() => this.runHook('before'))164 .then(result => {165 if (result instanceof Error) {166 Logger.error(result);167 }168 return this.runNextTestCase();169 })170 .catch(err => {171 if (err.sessionCreate) {172 throw err;173 }174 Logger.error(err);175 // testcase failed - this catch ensures that the after hook is being called176 return err;177 })178 .then(_ => {179 return this.runHook('after');180 })181 .catch(err => {182 if (err.code === 'ECONNREFUSED') {183 throw err;184 }185 if (!err.sessionCreate) {186 Logger.error(err);187 }188 // testsuite failed - this catch ensures that the global afterEach will always run189 return this.terminate('FAILED');190 })191 .then(_ => this.runGlobalHook('afterEach'))192 .catch(err => {193 if (err.sessionCreate) {194 throw err;195 }196 Logger.error(err);197 // catching errors thrown inside the global afterEach198 return true;199 })200 .then(failures => {201 if (this.shouldRetrySuite()) {202 return this.retrySuite();203 }204 return failures;205 })...

Full Screen

Full Screen

cli.js

Source:cli.js Github

copy

Full Screen

...112 parseTestSettings(settings = {}) {113 this.initTestSettings(settings, this.baseSettings, this.argv, this.testEnv);114 return this;115 }116 runGlobalHook(key) {117 if (!Concurrency.isChildProcess()) {118 return this.globals.hooks[key].run();119 }120 return Promise.resolve();121 }122 validateTestEnvironments() {123 for (let i = 0; i < this.testEnvArray.length; i++) {124 if (!(this.testEnvArray[i] in this.baseSettings.test_settings)) {125 throw new Error(`Invalid testing environment specified: ${this.testEnvArray[i]}. Available environments are: ${this.availableTestEnvs.join(', ')}`);126 }127 }128 return this;129 }130 ///////////////////////////////////////////////////////////////////////////////////////////////////////////131 // Concurrency related132 ///////////////////////////////////////////////////////////////////////////////////////////////////////////133 parallelMode(modules = null) {134 let testWorkerMode = this.test_settings.testWorkersEnabled && !this.testRunner.isTestWorker();135 if (testWorkerMode && Array.isArray(modules) && modules.length <= 1) {136 return false;137 }138 return this.testEnvArray.length > 1 || testWorkerMode;139 }140 setupConcurrency() {141 WebDriver.concurrencyEnabled = this.isConcurrencyEnabled();142 if (this.isWebDriverManaged()) {143 WebDriver.createInstances(this.baseSettings, this.argv, this.testEnvArray);144 }145 this.concurrency = new Concurrency(this.test_settings, this.argv);146 return this;147 }148 isWebDriverManaged() {149 return this.test_settings.webdriver.start_process && !Concurrency.isChildProcess();150 }151 isConcurrencyEnabled(modules) {152 if (!this.testRunner) {153 throw new Error('No test runner available.');154 }155 return this.testRunner.supportsConcurrency && this.parallelMode(modules);156 }157 startWebDriver() {158 if (!this.isWebDriverManaged()) {159 return Promise.resolve();160 }161 return WebDriver.startInstances().catch(err => {162 Logger.error(err);163 if (err.errorOut) {164 Logger.error(err.errorOut);165 }166 throw err;167 });168 }169 stopWebDriver() {170 if (!this.isWebDriverManaged()) {171 return Promise.resolve();172 }173 return WebDriver.stopInstances();174 }175 ///////////////////////////////////////////////////////////////////////////////////////////////////////////176 // Test runner related177 ///////////////////////////////////////////////////////////////////////////////////////////////////////////178 executeTestRunner(modules) {179 return this.testRunner.run(modules);180 }181 createTestRunner() {182 this.testRunner = Runner.create(this.test_settings, this.argv, {183 globalHooks: this.globals ? this.globals.hooks : null184 });185 this.processListener.setTestRunner(this.testRunner);186 return this;187 }188 /**189 *190 * @param [done]191 * @return {*}192 */193 runTests(done = null) {194 return this.runGlobalHook('before')195 .then(_ => {196 return Runner.readTestSource(this.test_settings, this.argv);197 })198 .then(modules => {199 if (this.isConcurrencyEnabled(modules)) {200 return this.testRunner.runConcurrent(this.testEnvArray, modules)201 .then(exitCode => {202 if (exitCode > 0) {203 this.processListener.setExitCode(exitCode);204 }205 });206 }207 return this.executeTestRunner(modules);208 })209 .catch(err => {210 if (err.detailedErr) {211 err.data = err.detailedErr;212 }213 Logger.error(err);214 if (err.data) {215 Logger.warn(' ' + err.data);216 }217 return err;218 })219 .then(errorOrFailed => {220 if (errorOrFailed instanceof Error || errorOrFailed === true) {221 try {222 this.processListener.setExitCode(5);223 } catch (e) {224 console.error(e);225 }226 }227 return this.runGlobalHook('after')228 .then(result => {229 return errorOrFailed;230 });231 })232 .catch(err => {233 Logger.error(err);234 console.log('');235 try {236 this.processListener.setExitCode(5);237 } catch (e) {238 console.error(e);239 }240 return err;241 })...

Full Screen

Full Screen

runJest.js

Source:runJest.js Github

copy

Full Screen

...219 if (globalConfig.detectOpenHandles) {220 collectHandles = collectNodeHandles();221 }222 if (hasTests) {223 await runGlobalHook({allTests, globalConfig, moduleName: 'globalSetup'});224 }225 const results = await new TestScheduler(226 globalConfig,227 {228 startRun,229 },230 testSchedulerContext,231 ).scheduleTests(allTests, testWatcher);232 sequencer.cacheResults(allTests, results);233 if (hasTests) {234 await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'});235 }236 return processResults(results, {237 collectHandles,238 isJSON: globalConfig.json,239 onComplete,240 outputFile: globalConfig.outputFile,241 outputStream,242 testResultsProcessor: globalConfig.testResultsProcessor,243 });...

Full Screen

Full Screen

runGlobalHook.js

Source:runGlobalHook.js Github

copy

Full Screen

...72 *73 * This source code is licensed under the MIT license found in the74 * LICENSE file in the root directory of this source tree.75 */76async function runGlobalHook({allTests, globalConfig, moduleName}) {77 const globalModulePaths = new Set(78 allTests.map(test => test.context.config[moduleName])79 );80 if (globalConfig[moduleName]) {81 globalModulePaths.add(globalConfig[moduleName]);82 }83 if (globalModulePaths.size > 0) {84 for (const modulePath of globalModulePaths) {85 if (!modulePath) {86 continue;87 }88 const correctConfig = allTests.find(89 t => t.context.config[moduleName] === modulePath90 );...

Full Screen

Full Screen

Jest Testing Tutorial

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.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful