Jasmine JavaScript Testing Framework Jasmine Configuration and Reporters 3 — Questions and Answers
Question 1: How do you filter which specs run using the Jasmine CLI?
- --filter="pattern" (Correct answer)
- --grep="pattern"
- --match="pattern"
- --spec="pattern"
Correct answer: --filter="pattern"
The --filter flag accepts a regex string and Jasmine runs only specs whose full name matches the pattern.
Question 2: What does the helpers option in jasmine.json specify?
- Glob patterns for files loaded before any spec files run (Correct answer)
- Utility functions exported to all specs automatically
- Override values that augment the main jasmine.json
- Fixture data files loaded for each spec
Correct answer: Glob patterns for files loaded before any spec files run
helpers are loaded after the Jasmine framework but before spec files, making them ideal for setting up custom matchers or global configuration.
Question 3: Which reporter interface method is called exactly once when the Jasmine test run begins?
- jasmineStarted(result) (Correct answer)
- onStart(result)
- runStarted(result)
- testBegin(result)
Correct answer: jasmineStarted(result)
jasmineStarted(result) is the first reporter method called, receiving the total spec count so reporters can track progress.
Question 4: What does jasmine.getEnv().allowRespy(true) enable?
- Calling spyOn on a method that is already a spy (Correct answer)
- Running specs in any order without a seed
- Re-running failed specs after the suite completes
- Using async return values in spy configurations
Correct answer: Calling spyOn on a method that is already a spy
By default Jasmine throws when you spy on an already-spied method; allowRespy(true) suppresses that error.
Question 5: Which jasmine.json option stops Jasmine from running further specs after a set number of failures?
- failFast: true (Correct answer)
- stopOnFailureCount: n
- maxFailures: n
- haltOnError: n
Correct answer: failFast: true
failFast: true stops the run after the first failure; for a specific count, you can also use the stopSpecOnExpectationFailure option per spec.
Question 6: What is the purpose of jasmine.getEnv().clearReporters()?
- Removes all currently registered reporters from the environment (Correct answer)
- Clears the output buffer of the active reporter
- Resets reporter statistics without removing reporters
- Disables only the default ConsoleReporter
Correct answer: Removes all currently registered reporters from the environment
clearReporters() removes every registered reporter, which is useful when you want to install only a custom reporter without the default output.
How do you filter which specs run using the Jasmine CLI?