Explore your skills in using Jest command-line interface with this quiz, featuring questions on common commands, options, and their correct usage. Deepen your understanding of jest CLI switches, configuration, and practical scenarios for test execution.
Which Jest CLI option allows you to only run tests that match a specific filename pattern, such as files ending in '.spec.js'?
Explanation: The --testPathPattern option lets you specify a regex pattern to match test file paths, which is useful for targeting tests like '.spec.js'. --runFiles is not a recognized Jest CLI option and would not work. --fileMatch sounds plausible but is not a valid Jest command. --grep is not applicable in Jest for file patterns; it's used differently in other test tools.
When running your tests with Jest, which CLI flag ensures that results for each individual test are displayed, rather than a summarized output?
Explanation: --verbose will display all test results individually, giving more detailed output for test suites and test cases. --detailed and --list are not valid Jest CLI options, although they sound like they might be. --print-each is not an actual Jest flag, so it would not have the intended effect.
Which sequence would you use to debug Jest tests using Node's built-in inspector from the CLI?
Explanation: Running node --inspect-brk with the path to the Jest binary starts Jest in debug mode, allowing inspection with developer tools. The flag --debug-break is not recognized by the Jest CLI. node-debug jest is not a recommended or standard approach. --inspectDebugger is not a valid CLI flag.
If you want Jest to only run tests related to files that have been changed since the last commit, which CLI flag should you use?
Explanation: --onlyChanged instructs Jest to focus on tests related to recently changed files, optimizing test runs in active development. --changedFiles and --since-changed are not valid Jest options, though they sound logical. --updateSnapshot updates snapshot files but does not filter tests by file changes.
Which Jest CLI option allows you to set a different test environment, such as switching from 'jsdom' to 'node' for tests running in a Node.js context?
Explanation: The --env option allows you to explicitly specify the test environment, for example setting it to 'node' for backend-style tests. --setEnvironment and --environmentNode are not valid CLI flags in Jest. --context is used for a different purpose and does not change the test environment.