Explore essential concepts of Deno's built-in test runner with beginner-friendly questions covering its features, basic syntax, and common practices in automated testing. Ideal for users wanting to strengthen their understanding of Deno’s native test utilities and capabilities.
Which function is used to define a test when using Deno’s built-in test runner?
Explanation: Deno.test is the correct function for defining a test in Deno's built-in test runner. runTest and testIt are not recognized functions in this system, though they may appear in other environments. describe is typically used for grouping tests in some frameworks, but not as a test-defining function in this context.
When creating a test in Deno, how should you provide the name or description of the test?
Explanation: The test's name or description should be passed as the first argument string to Deno.test. Comments above the test do not serve as identifiers for the test runner. Using an external doc file or only naming the file does not inform the test runner of the test’s intent.
Which function can be used for simple value comparison assertions in a Deno test?
Explanation: assertEquals is the correct function for checking if two values are equal in Deno tests. assertSame, matchEqual, and validateEqual are not valid assertion functions recognized by Deno's built-in tools, making them incorrect choices.
How does Deno’s test runner typically identify which files to run as test files?
Explanation: By default, Deno’s test runner looks for files ending with _test.ts or .test.ts. Scanning all files in the src directory is not standard behavior. Only searching for files named 'test.js' or requiring a main function does not align with Deno's conventions.
Which command should you use to run all tests in a Deno project?
Explanation: The deno test command is specifically designed to execute all detected test files. deno run is used to run scripts but not specifically for testing. deno check is for type checking, and deno execute is not a recognized command.
What feature does Deno’s test runner provide to support tests using asynchronous code, such as awaiting a fetch call?
Explanation: Deno's test runner allows test functions to be async, enabling the direct use of await within tests. Tests do not need to be strictly synchronous, nor do they require a callback pattern. It's incorrect to say asynchronous code cannot be tested.
Where are commonly used assertion functions like assert and assertEquals found for Deno tests?
Explanation: Assertion functions are provided via an official standard library, which must be explicitly imported into each test file. They are not part of the global Deno object nor automatically available in every test. Third-party modules are not necessary for basic assertions.
How can you logically group related tests together in Deno's testing system for better organization?
Explanation: The common practice is to prefix related test names so they appear grouped in test output. There is no group function or built-in way to nest Deno.test calls. The file name suffix .group.ts is not recognized for grouping tests.
What information does Deno's test runner display if a test fails?
Explanation: The runner provides the name of each failed test along with a clear error message to help identify issues. Displaying only the number of failed tests or just the filename is not sufficiently informative. It is incorrect to say no output is given for failed tests.
How can you run only tests with names matching a specific pattern using Deno’s built-in test runner?
Explanation: The --filter flag allows you to target test names matching a specified pattern, running only those tests. Manually editing out other tests or renaming files is inefficient and not required. Changing the default directory does not filter test names.