JavaScript/TypeScript

JavaScript/TypeScript

Object Type Check By User Defined Type Guard with Record Type

I wrote the following article before. When we want to access a property of an object, we must somehow tell the...
JavaScript/TypeScript

TypeScript input validation by Method Decorators

While I read a book on API Design Patterns, I found decorators were used in the examples. It looks like this. @ge...
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

TS2322 error when trying to add a property to an anonymous object

TS2322 error happens when trying to add a property to an anonymous object. Haven't you faced this case where you need t...
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

Reduce the number of if-else and switch-case conditional clauses

Have you found a function is not readable because of lots of conditional clauses such as if-else or switch-case? It's t...
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...
Copied title and URL