Unit Test

JavaScript/TypeScript

A good way to write our own Node-RED node for the testability

I have used Node-RED for more than 3 years for my working project. I came up with a good idea to write our own node for...
JavaScript/TypeScript

Top-Level function cannot be stubbed if it is exported by an asterisk

A top-level function is not a part of an object. If we need to stub it, we need to have an object that has the target f...
JavaScript/TypeScript

What is the difference between Stub and Mock

In a unit test, we need to replace a real behavior with a test object but the variable name is sometimes xxxxStub for m...
JavaScript/TypeScript

TypeScript Stub Date and timer friends functions with sinon

When Date class, timer friends functions like setTimeout, and setInterval are used in a function, we need to control th...
JavaScript/TypeScript

How to determine test values for unit testing

Are you a beginner at unit testing? Are you not confident enough to choose the test cases? You are not alone. Let's lea...
JavaScript/TypeScript

TypeScript Stub Top Level function by Sinon

Functions called in a different function are not always class members. They are often top-level functions which are not...
JavaScript/TypeScript

How to mock fs.readdir and fs.readFile for unit testing

Reading a directory to get a file list and then, loading the file one by one. You might have seen such a function. If i...
JavaScript/TypeScript

How to inject user input data for unit tests

Some console applications require user inputs. For those inputs, we need to write unit tests. If we using readline modu...
JavaScript/TypeScript

How to start Unit Testing in TypeScript with mocha and chai

Writing unit tests is an important step to be an intermediate developer from a beginner. The developers who can't write...
JavaScript/TypeScript

Chai Object array comparison

I needed to write tests for object array but I spent time on how to write it. I write down how to do it to save my time...
Copied title and URL