+1 vote
in NodeJS Essentials by

What's a stub? Name a use case!

1 Answer

0 votes
by

Stubs are functions/programs that simulate the behaviors of components/modules. Stubs provide canned answers to function calls made during test cases.

An example can be writing a file, without actually doing so.

var fs = require('fs')

var writeFileStub = sinon.stub(fs, 'writeFile', function (path, data, cb) {  

  return cb(null)

})

expect(writeFileStub).to.be.called

writeFileStub.restore()

Related questions

+1 vote
asked May 30, 2020 in NodeJS Essentials by SakshiSharma
+1 vote
asked May 31, 2020 in NodeJS Essentials by Robindeniel
...