Who thinks that is VTEST, the rest, right? Okay, yep. So everyone say VTEST, so that's the meaning. It's like, when I first come to VIT, I thought it was VITE, because we say LITE, so it's supposed to be VITE, right? But then I say, no, it's VIT. So like, what? Anyway, that's the name mean.
So VTEST is what was developed by the VIT team for VIT power, okay, VIT device, VIT, by VIT power projects, but now it's become, it's not just limited to VIT power projects, so it probably can use for other webpack project also. It's a JavaScript and TypeScript unit testing framework, and it just released 1.00 version also two days ago. Wow. So it's stable to use. It's very fast. I can't vow for this, because we use at work, we switch from CHESS to VTEST and it's really, really fast. It's come with TypeScript and CHESSX support out of the box, and of course, the syntax is almost the same with CHESS and Mocha and Chai, and you can use any of them, which means your learning curve, or your migration, will not take that much of effort to do it, but better.
Okay, so how better, let's say, unit test. For unit test, disclaimer here, first and foremost, for unit test, it's important to know that we don't test every unit code. You don't test every piece of code. Every if and else, it doesn't mean you need to test everything of them. If you have to test two plus two equal four, that's fact. You don't test that. So just make sure that you don't override your test. Second thing is, for unit test, always use mock. If anything come outside, if anything you import and not part of the code, you should mock it, because you never know what's going on that, from the other side, can affect your test. And lastly, always make sure that you do functional testing here, that means logic, not everything else, not interaction and so on. Let's take a look about use search, the hook, with the code, the logic behind. So in this logic, I have two things. First is we are going to fill out the list of input item according to the search. So this is the two main logic here that I need to test separately. So for that, for testing the hook, VTest wouldn't work out of the box with React hooks. Because VTest is for JavaScript and TypeScript plan, the vanilla one. If you want to test something special like hooks, because interactive, you need to make sure that you need to use external library to help with that. So in this case, using testing library React hooks is the package that allow you to mimic and render the React hooks according to React standard, and then you can test on it. So how we do that? First, we just import render hook from testing library React hooks, and then we've run the function, trigger the function to render the hooks in the context of React, and we get back the result, and the result has the field called current, where you can� sorry.
Comments