Pro Coder Quiz

1. Which command is used to run only tests that match a specified name pattern in Jest?
A) jest
run
B) jest --only
C) jest --test
D) jest -t
Correct Answer: Option D
2. Which method is used in Jest to simulate user events on a React component?
A) triggerEvent()
B) simulate()
C) fireEvent()
D) dispatchEvent()
Correct Answer: Option C
3. What
is the function of jest.fn()?
Correct Answer: Option B
4. What does the toBe matcher in Jest primarily check for?
A) Object equalityCorrect Answer: Option D
5. Which function is used to clean up after tests in Jest?
A) cleanup()
B) tearDown()
C) afterEach()
D) cleanUp()
Correct Answer: Option C
6. Which method is used in Jest to mock a module's default export?
A) mockDefault()Correct Answer: Option D
7. How can you skip a test in Jest?
A) Use xtest() instead of test().
B) Add skip: true to the test case.
C) Comment out the test code.
D) Use jest.skip() within the test.
Correct Answer: Option A
8. What does the toThrow matcher in Jest check for?
A) If a function has been calledCorrect Answer: Option B
9. Which Jest configuration file is used by default?
A) jest.jsonCorrect Answer: Option B
10. What is the purpose of the only function in Jest?
A) To run only one test case.
B) To isolate a test suite
C) To run only a specific number of tests
D) To
run a specific test case in isolation
Correct Answer: Option D
11. Which
Jest configuration is used to set up a directory for coverage reports?
A) coverageDirectory
B) coverageReportDir
C) coverageDir
D) reportCoverageDir
Correct Answer: Option A
12. How can you test asynchronous code in Jest?
A) Using setTimeout()
B) Using async/await or done callback
C) Wrapping code in a try-catch block
D) Using Promise.resolve()
Correct Answer: Option B13. Which Jest method is used to reset the state of mocks?
A) jest.resetAllMocks()
Correct Answer: Option C
14. What is the purpose of the jest.spyOn method?
A) To create a spy function to track calls
B) To set up mock implementations for modules
C) To execute asynchronous tests
D) To define test cases
Correct Answer: Option A
15. Which command is used to run Jest in watch mode?
A) jest
--watch
B) jest watch
C) jest -w
D) jest --mode=watch
Correct Answer: Option A