Jasmine JavaScript Testing Framework Jasmine Test Suite Organization 2 — Questions and Answers
Question 1: How do you skip a single Jasmine spec without deleting it?
- xit() (Correct answer)
- it.skip()
- it.ignore()
- pendingTest()
Correct answer: xit()
xit() marks a single spec as pending, so it appears in results as pending rather than being executed.
Question 2: Which function inside an it() block marks that spec as pending in Jasmine?
- pending() (Correct answer)
- it.todo()
- skip()
- jasmine.pending()
Correct answer: pending()
Calling pending() inside an it() block immediately halts the spec and records it as pending in the results.
Question 3: Can Jasmine describe blocks be nested inside each other?
- Yes, to any depth (Correct answer)
- No, only a single level is supported
- Yes, but only two levels deep
- Yes, but nesting is restricted to beforeAll blocks
Correct answer: Yes, to any depth
Jasmine supports unlimited nesting of describe blocks, allowing a hierarchical organization of specs.
Question 4: Which function runs a callback exactly once before any specs in a describe block execute?
- beforeAll() (Correct answer)
- setup()
- initOnce()
- beforeSuite()
Correct answer: beforeAll()
beforeAll() is called one time before the first spec in its describe block, unlike beforeEach() which runs every time.
Question 5: When both an outer and an inner describe have a beforeEach, in what order do they run?
- Outer beforeEach runs first, then inner beforeEach (Correct answer)
- Inner beforeEach runs first, then outer beforeEach
- They run in parallel simultaneously
- Only the innermost beforeEach runs
Correct answer: Outer beforeEach runs first, then inner beforeEach
Jasmine executes beforeEach hooks from outermost to innermost describe, building up shared state before the spec runs.
Question 6: What does fit() do in Jasmine?
- Focuses on a single spec so Jasmine runs only focused items (Correct answer)
- Runs the spec first regardless of order
- Marks the spec as a fixture to be reused
- Filters specs by name using a regex
Correct answer: Focuses on a single spec so Jasmine runs only focused items
fit() focuses an individual spec; when any focused specs exist, Jasmine skips all non-focused ones.
How do you skip a single Jasmine spec without deleting it?