Jasmine JavaScript Testing Framework Jasmine Configuration and Reporters 1 — Questions and Answers
Question 1: What file is typically used to configure Jasmine in a Node.js project?
- spec/support/jasmine.json (Correct answer)
- .jasminerc
- jasmine.config.js
- package.json exclusively
Correct answer: spec/support/jasmine.json
By convention Jasmine looks for its configuration at spec/support/jasmine.json unless overridden via the --config CLI flag.
Question 2: Which jasmine.json option specifies the root directory from which specs are located?
- spec_dir (Correct answer)
- specDir
- testDir
- suiteDir
Correct answer: spec_dir
spec_dir sets the base directory Jasmine uses to resolve the paths defined in spec_files and helpers.
Question 3: What does the spec_files array in jasmine.json define?
- Glob patterns matching the test files Jasmine should load (Correct answer)
- Exact file names of individual test files
- The execution order for test files
- The reporter modules to use
Correct answer: Glob patterns matching the test files Jasmine should load
spec_files accepts an array of glob patterns relative to spec_dir, and Jasmine loads all matching files as test specs.
Question 4: How do you register a custom reporter in a Jasmine Node.js setup?
- jasmine.addReporter(reporterObject) (Correct answer)
- jasmine.setReporter(reporterObject)
- jasmine.reporter.add(reporterObject)
- jasmine.use(reporterObject)
Correct answer: jasmine.addReporter(reporterObject)
addReporter() registers an additional reporter object alongside the default one; you can add multiple reporters.
Question 5: What does the random option in jasmine.json control?
- Whether specs run in a randomized order each time (Correct answer)
- Whether Jasmine generates random test data
- Whether spy return values are randomized
- Whether a random subset of specs is selected
Correct answer: Whether specs run in a randomized order each time
Setting random: true causes Jasmine to shuffle spec execution order, helping catch order-dependent test bugs.
Question 6: What does the stopSpecOnExpectationFailure option do in Jasmine?
- Stops the current spec after the first failed expectation (Correct answer)
- Stops the entire suite after any spec fails
- Prevents afterEach from running on failure
- Throws immediately instead of recording the failure
Correct answer: Stops the current spec after the first failed expectation
When true, stopSpecOnExpectationFailure causes Jasmine to abort the current spec at the first failed expect() rather than continuing.
What file is typically used to configure Jasmine in a Node.js project?