Jasmine JavaScript Testing Framework Jasmine Configuration and Reporters 2 — Questions and Answers
Question 1: How do you provide a seed for reproducible random spec order in Jasmine?
- jasmine --seed=1234 on the CLI (Correct answer)
- jasmine --random-seed=1234 on the CLI
- jasmine.randomSeed(1234) in code
- JASMINE_SEED=1234 as an environment variable
Correct answer: jasmine --seed=1234 on the CLI
Passing --seed=<value> via the CLI fixes the randomization seed so the same order is reproduced on subsequent runs.
Question 2: Which reporter interface method does Jasmine call when a spec begins executing?
- specStarted(result) (Correct answer)
- onSpecStart(result)
- specBegin(result)
- startSpec(result)
Correct answer: specStarted(result)
specStarted(result) is one of the standard reporter interface methods; the result object contains the spec's description and id.
Question 3: What does setting failFast: true do in Jasmine configuration?
- Stops the entire test run after the first spec failure (Correct answer)
- Marks all pending specs as failures
- Applies a short timeout to every async spec
- Throws on any unmatched expectation
Correct answer: Stops the entire test run after the first spec failure
failFast: true causes Jasmine to halt execution immediately after the first failing spec, useful for fast feedback.
Question 4: Which reporter method does Jasmine call when a describe suite finishes?
- suiteDone(result) (Correct answer)
- jasmineDone(result)
- suiteComplete(result)
- afterSuite(result)
Correct answer: suiteDone(result)
suiteDone(result) fires each time a describe block completes; jasmineDone fires once when the entire run finishes.
Question 5: What is the direct CLI command to run Jasmine specs in a Node.js project?
- npx jasmine (Correct answer)
- jasmine-runner
- node jasmine.js
- npm jasmine
Correct answer: npx jasmine
npx jasmine discovers and runs specs using your project's jasmine.json configuration without a global install.
Question 6: What does jasmine.getEnv().execute() do?
- Triggers execution of all registered suites and specs (Correct answer)
- Returns the current Jasmine environment configuration object
- Resets the environment back to its initial state
- Registers a new empty suite in the environment
Correct answer: Triggers execution of all registered suites and specs
execute() is the method that actually starts the Jasmine test run after all describes and specs have been registered.
How do you provide a seed for reproducible random spec order in Jasmine?