NodeJS by Example: Test Runner
The test runner is a new addition to the NodeJS APIs. You can now create and run tests use just the standard library. Tests create via the test module are made up of a single function that can be evaluated one of three ways. |
|
The test runner is only available under the node: schema We will use the assert module to test our code |
|
1. A synchronous function that throws an exception. This test passes |
|
2. A synchronous function that throws an exception. This test fails. The test runner will catch the exception and report it as a failure |
|
3. An asynchronous function that returns a promise that rejects. This test fails |
|
4. A Callback function that is called with a single argument. This test fails |
|
5. You can also skip tests in one of two ways, both include an optional message to pass through |
|
6. Like most testing frameworks you can declare a test suit using the describe and it functions
|
|
You can then run it from the command line |
|