The assertion library used to support snapshot testing, but it was unstable and removed. Now, efforts are being made to bring it back. Node.js testing library provides a range of features, including synchronous and asynchronous testing, BDD keywords, filtering, hooks, and mocking. It also offers various reporters, such as spec, tap, and dot.
Very handy. One thing, fun fact about the assertion library, we used to ship snapshot testing so you could test snapshot, but we decided to remove it because it was not stable enough. So we're trying to bring it back because I personally love snapshot testing.
And you can also obviously run a synchronous test with different kinds of level. So you have a top level and sub testing. This is quite powerful in the Node.js because most of the time they are going to be asynchronous.
And you can also use the BDD keywords like describe and it, they do the same thing. It's just another syntax for people who want to use behavior-driven testing. Node.js testing library also provides some keywords like to do, skip and only. So you can filter your test based on, you can write, you know that you will want to write the test later so you mark it as to do, you want to skip it because it's not ready yet, you can just skip it. So it provides a full, full utilities for testing.
Obviously all the hooks, before, before all, after, after all. This is our standard features that Node.js provides out of the box so you don't need to install any other library. You can filter by name pattern. So for example, if you want to write only the test that contain the word foo in the description, you can do it. So in this example, it will only execute foo but it will skip bar, this is very handy.
You can mock. It has the, out of the box, the mocking functionality so you can mock object functions, whatever, you don't need libraries like xenon and it comes everything out of the box.
Yeah, you can choose your own reporter. So most people use spec, which is the default one. This is what it looks like. But you can also use tap if you like YAML output. I personally don't like YAML, tap, because it's very verbose, but it can be parsed by machines. So it's actually pretty good for automations. And this is what tap output looks like. So pretty standard. We also have dot as a reporter. So if you are familiar with something like PHP units, yeah, the output is just a dot. And an X if it failed. I haven't used it yet.
Comments