














































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































































Question 1. Which QUnit method is used to declare a test case? A) QUnit.run() B) QUnit.test() C) QUnit.assert() D) QUnit.define() Answer: B Explanation: QUnit.test() defines a single test function containing the test logic. Question 2. In the Arrange‑Act‑Assert pattern, the “Arrange” step typically involves: A) Executing the code under test B) Verifying the result C) Setting up test data and environment D) Cleaning up after the test Answer: C Explanation: “Arrange” prepares inputs, mocks, and any necessary state before the code runs. Question 3. Which of the following assertions checks for a truthy value? A) assert.equal() B) assert.ok() C) assert.strictEqual() D) assert.deepEqual() Answer: B Explanation: assert.ok() passes when its argument evaluates to true in a boolean context. Question 4. What is the main difference between assert.equal() and assert.strictEqual()? A) assert.equal() compares objects deeply, assert.strictEqual() does shallow comparison
B) assert.equal() uses ==, assert.strictEqual() uses === C) assert.equal() works only with numbers, assert.strictEqual() works with strings D) There is no difference; they are aliases Answer: B Explanation: assert.equal() performs non‑strict (==) comparison, while assert.strictEqual() uses strict (===) comparison. Question 5. Which assertion would you use to verify that two arrays have identical contents, regardless of order? A) assert.deepEqual() B) assert.notDeepEqual() C) assert.equal() D) assert.step() Answer: A Explanation: assert.deepEqual() recursively checks structural equality, including array elements and order. (If order does not matter, you would sort first.) Question 6. To test that a function throws an error, which assertion should be used? A) assert.ok() B) assert.throws() C) assert.rejects() D) assert.expect() Answer: B Explanation: assert.throws() expects the supplied function to throw an exception. Question 7. Which of the following is the correct way to test a rejected Promise in QUnit? A) assert.throws(promise)
C) The UI for the test runner toolbar D) A configuration object for QUnit Answer: B Explanation: #qunit-fixture is a DOM element cleared after each test, ensuring a clean environment for DOM‑related tests. Question 11. Which command installs QUnit via npm? A) npm install --save-dev qunit B) npm get qunit C) npm download qunit D) npm add qunit Answer: A Explanation: npm install --save-dev qunit adds QUnit as a development dependency. Question 12. When running QUnit tests in a browser, which toolbar button hides all passed tests? A) “Hide passed” B) “Show failures only” C) “Toggle globals” D) “No try‑catch” Answer: A Explanation: The “Hide passed” button collapses successful tests to focus on failures. Question 13. Which QUnit configuration option disables automatic test start, allowing you to call start() manually? A) autostart: false B) reorder: true
C) scrolltop: false D) filter: '' Answer: A Explanation: Setting QUnit.config.autostart = false prevents QUnit from running tests immediately. Question 14. How can you listen for the start of each individual test using QUnit’s reporter API? A) QUnit.on('testStart', callback) B) QUnit.testBegin(callback) C) QUnit.hook('testStart', callback) D) QUnit.listen('testStart', callback) Answer: A Explanation: QUnit.on(eventName, handler) registers listeners; 'testStart' fires at the beginning of each test. Question 15. Which of the following statements about assert.async() is true? A) It returns a function that must be called to signal test completion. B) It automatically resolves promises. C) It can only be used inside beforeEach hooks. D) It disables timeout handling. Answer: A Explanation: assert.async() creates a “done” callback; the test stays pending until that callback is invoked. Question 16. If a test returns a Promise, what does QUnit do with that Promise? A) Ignores it completely
A) Using a CDN script tag B) Importing via ES6 module from node_modules C) Adding a tag with rel="qunit" D) Installing via npm and bundling with Webpack Answer: C Explanation: QUnit is loaded via Question 22. How can you limit the maximum time a QUnit test may run before being considered hung? A) QUnit.config.timeout = 2000 B) QUnit.setTimeout(2000) C) assert.timeout(2000) D) QUnit.config.testTimeout = 2000 Answer: A Explanation: QUnit.config.testTimeout (or simply QUnit.config.timeout in newer versions) sets the global timeout in milliseconds. Question 23. Which of the following is the correct syntax to create a nested module named “API – Users”? A) QUnit.module('API – Users', function(){ … }) B) QUnit.module('API', function(){ QUnit.module('Users', function(){ … }) }) C) QUnit.module('API – Users') D) QUnit.nestedModule('API – Users') Answer: B Explanation: Nested modules are achieved by calling QUnit.module inside another module’s callback. Question 24. When running QUnit tests via the CLI, which flag filters tests by name pattern? A) --grep B) --filter C) --match D) --testName Answer: A
Answer: A Explanation: While QUnit does not have a built‑in “calls” assertion, you can manually compare a spy’s callCount using assert.equal(). Question 28. What is the purpose of the “no try‑catch” toolbar option? A) It disables QUnit’s internal try‑catch wrapper, allowing errors to propagate to the browser console B) It prevents any test from using try‑catch statements C) It forces all assertions to be wrapped in try‑catch automatically D) It disables the global error handler for the page Answer: A Explanation: Turning off “no try‑catch” lets errors bubble up, which can be useful for debugging in the console. Question 29. Which CLI output format is commonly used for integration with continuous‑integration systems? A) HTML B) TAP (Test Anything Protocol) C) JSONP D) XML Answer: B Explanation: TAP is a simple line‑based format that many CI tools can parse for test results. Question 30. If you need to run a test only once, regardless of how many times its module is instantiated, which hook should you use? A) beforeEach B) afterEach
C) before D) after Answer: C Explanation: The before hook runs a single time before any tests in its module, even if the module is re‑instantiated. Question 31. Which of the following statements about assert.rejects() is true? A) It only works with synchronous functions B) It returns a Promise that resolves when the supplied Promise rejects C) It automatically retries the Promise until it resolves D) It cannot verify the error message Answer: B Explanation: assert.rejects() returns a Promise that fulfills when the tested Promise rejects, allowing you to await it. Question 32. What does the QUnit.config.reorder option control? A) Whether tests are executed in alphabetical order B) Whether QUnit shuffles test order to detect inter‑test dependencies C) Whether the UI toolbar is displayed D) Whether async tests are run before sync tests Answer: B Explanation: When reorder is true (default), QUnit randomizes test order to surface hidden dependencies. Question 33. Which of the following best describes the purpose of code coverage tools like Istanbul when used with QUnit? A) They replace QUnit’s assertion library
A) qunit-cli B) qunit-node C) qunitjs D) qunit-browser Answer: A Explanation: The qunit-cli package supplies a command‑line runner that can also launch an HTML UI for Node environments. Question 37. How can you skip a particular test without removing its code? A) Comment it out B) Use QUnit.skip() instead of QUnit.test() C) Return early from the test function D) Set assert.expect(0) Answer: B Explanation: QUnit.skip() defines a test that is reported as skipped, preserving the code for later. Question 38. Which of the following hooks runs after all tests in a module have completed, even if some tests failed? A) afterEach B) beforeEach C) after D) before Answer: C Explanation: The after hook executes once after the module finishes, regardless of individual test outcomes.
Question 39. Which assertion would you use to verify that a DOM element with id “output” contains the text “Success”? A) assert.equal(document.getElementById('output').textContent, 'Success') B) assert.ok('#output') C) assert.deepEqual('#output', 'Success') D) assert.throws('#output') Answer: A Explanation: Directly comparing the element’s textContent with the expected string using assert.equal() validates the content. Question 40. What is the effect of setting QUnit.config.autostart = true? A) Tests will start automatically once QUnit is loaded B) Tests will never start unless start() is called manually C) All tests will be skipped D) QUnit will ignore any defined modules Answer: A Explanation: autostart true triggers immediate execution of the test suite after QUnit finishes loading. Question 41. Which of the following best explains the purpose of assert.verifySteps()? A) To assert that a given number of assertions have run B) To compare an array of recorded step labels against an expected sequence C) To verify that a promise resolves within a time limit D) To ensure that global variables are not leaked Answer: B Explanation: verifySteps() checks that the steps recorded via assert.step() match the expected order.
Question 45. Which of the following statements about QUnit’s CLI TAP output is correct? A) It produces XML files that can be parsed by Jenkins B) Each test result line starts with “ok” or “not ok” C) TAP output is only available in the browser UI D) TAP disables all asynchronous tests Answer: B Explanation: TAP follows a simple line format where passing tests are prefixed with “ok” and failures with “not ok”. Question 46. How can you temporarily disable a QUnit module without deleting its code? A) Comment out all its tests B) Use QUnit.module.skip() instead of QUnit.module() C) Set QUnit.config.module = null D) Rename the module to start with “_” Answer: B Explanation: QUnit.module.skip() defines a module that is ignored during execution, preserving its contents. Question 47. Which of the following is a correct way to assert that a function returns a Promise that resolves to 42? A) assert.equal(myFunc(), 42) B) return myFunc().then(value => assert.equal(value, 42)) C) assert.ok(myFunc() instanceof Promise) D) assert.throws(() => myFunc()) Answer: B
Explanation: Returning the Promise chain lets QUnit wait for it, and the then block asserts the resolved value. Question 48. What does the QUnit.config.scrolltop option control? A) Whether the page scrolls to the top after each test run B) Automatic scrolling to the first failed assertion C) Enabling smooth scrolling in the UI D) Disabling scrolling altogether during tests Answer: B Explanation: When true, QUnit scrolls the page to the first failed assertion after a test run. Question 49. Which of these is a valid way to create a custom assertion that checks if a number is positive? A) QUnit.assert.isPositive = function(value){ this.ok(value > 0, 'Number is positive'); } B) QUnit.addAssertion('isPositive', fn) C) assert.isPositive = function(value){ … } D) QUnit.createAssert('isPositive', fn) Answer: A Explanation: Extending QUnit.assert with a new method allows you to call assert.isPositive() in tests. Question 50. When a test fails because an unexpected global variable was created, which QUnit UI feature helps you locate the leak? A) “Hide passed” button B) “Check for globals” toggle C) “No try‑catch” checkbox D) “Filter” dropdown
D) It automatically counts steps recorded via assert.step() Answer: D Explanation: assert.expect() counts only assertion calls, not steps recorded by assert.step(). Question 54. If you need to run a test suite only in a headless browser environment, which tool can be combined with QUnit? A) Selenium WebDriver B) Puppeteer C) JSHint D) ESLint Answer: B Explanation: Puppeteer can launch a headless Chrome instance and execute QUnit tests programmatically. Question 55. Which hook would you use to perform an expensive asynchronous setup only once for a module? A) beforeEach (with async) B) before (with async) C) afterEach (with async) D) after (with async) Answer: B Explanation: The before hook runs once before any test in the module; it can return a Promise for async setup. Question 56. How does QUnit determine whether a test is asynchronous? A) By checking if the test function takes a “done” argument B) By inspecting the function’s length property
C) By detecting a returned Promise or the use of assert.async() D) By reading a comment annotation in the test code Answer: C Explanation: QUnit treats a test as async if it returns a Promise or if assert.async() is called. Question 57. Which of the following is the correct way to assert that a DOM element does NOT exist? A) assert.notOk(document.getElementById('missing')) B) assert.equal(document.getElementById('missing'), null) C) Both A and B are correct D) Neither; QUnit has no built‑in “not exists” assertion Answer: C Explanation: Both assert.notOk(null) and assert.equal(null, null) successfully verify non‑existence. Question 58. When using QUnit’s CLI with the --reporter option set to “json”, what is the primary benefit? A) Faster test execution B) Structured machine‑readable output for CI pipelines C) Automatic generation of HTML coverage reports D) Enabling the browser UI in the terminal Answer: B Explanation: The JSON reporter emits a detailed JSON object describing test results, useful for automated processing. Question 59. Which of the following statements about QUnit’s “module” feature is true? A) Modules cannot be nested