Jasmine JavaScript Testing Framework Jasmine Test Suite Organization 1 — Questions and Answers
Question 1: Which Jasmine function defines a group of related test specs?
- describe() (Correct answer)
- suite()
- group()
- context()
Correct answer: describe()
describe() is Jasmine's primary way to group specs into a named suite, and it can be nested.
Question 2: Which Jasmine function defines a single test specification?
- it() (Correct answer)
- test()
- spec()
- check()
Correct answer: it()
it() creates an individual spec; the string argument is the human-readable description shown in results.
Question 3: Which function runs a setup callback before each spec inside a describe block?
- beforeEach() (Correct answer)
- setup()
- before()
- onEach()
Correct answer: beforeEach()
beforeEach() registers a function that Jasmine calls before every it() in its containing describe block.
Question 4: What does afterAll() do within a Jasmine describe block?
- Runs once after all specs in the block have completed (Correct answer)
- Runs a teardown after every individual spec
- Tears down only the first spec in the block
- Runs at the very end of the entire test file
Correct answer: Runs once after all specs in the block have completed
afterAll() fires a single time after every spec inside its describe block finishes, useful for expensive teardown.
Question 5: How do you disable an entire describe suite without deleting it?
- xdescribe() (Correct answer)
- describe.skip()
- describe.ignore()
- skipDescribe()
Correct answer: xdescribe()
Prefixing describe with x (xdescribe) marks all contained specs as pending without removing any code.
Question 6: How do you focus Jasmine so only specific describe blocks run?
- fdescribe() (Correct answer)
- describe.only()
- focusDescribe()
- describe.focus()
Correct answer: fdescribe()
fdescribe() focuses the suite; Jasmine runs only focused suites and specs when any focus is detected.
Which Jasmine function defines a group of related test specs?