Pro Coder Quiz

CapDev Harbinger Group

ProCoder Quiz of the Month - Dec 2023

Top 3 Winners:
Azhar Sofi, Deepa Menghani and Kunal Shete

Congratulations!!

Quiz Questions and answers are below:

 

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()?  

    A) It creates a new Jest instance.

    B) It creates a mock function.

    C) It executes asynchronous tests.

    D) It compares snapshots.

Correct Answer: Option B

4. What does the toBe matcher in Jest primarily check for?

    A) Object equality

    B) Variable type

    C) Truthiness

    D) Value equality

Correct 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()

    B) mockExport()

    C) jest.mockDefault()

    D) jest.mockImplementation()

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 called

    B) If an error has been thrown

    C) If an object is defined

    D) If a promise has been resolved

Correct Answer: Option B

9. Which Jest configuration file is used by default?

    A) jest.json

    B) jest.config.js

    C) jest.conf

    D) jest.config.json

Correct 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 B

13. Which Jest method is used to reset the state of mocks?

      A) jest.resetAllMocks()

      B) resetMocks()

      C) jest.clearAllMocks()

      D) clearMocks()


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


Last modified: Tuesday, 26 December 2023, 2:30 PM