Stubs are used when testing applications. They simulate the behavior of a given component or a module so that you can focus on just the part of the code you want to test. By using stubs in place of components irrelevant to the test, you won’t have to worry about external components impacting the results.
For example, if the component you are testing has a file reading operation before the part you expect to test, you can use a stub to simulate that behavior and return mock content without actually reading the file.
In Node, we use libraries like Sinon for this purpose.