I've got a really basic script I'd like to be able to add coverage to using node-tap:
const chalk = require('chalk')
module.exports = skip = type => console.log(chalk.blue(`Skipping generation of ${type} due to user selection`))
All it does is display a console.log message to the user (it's a command-line app).
I've written the following tap test for it:
// test/hello-world.js
const t = require('tap')
const skip = require('../scripts/skip')
t.test('skip() Returns the expected console message', async t => {
t.equal(skip('test'), "Skipping generation of test due to user selection`")
t.end()
})
But obviously that fails as I'm not returning that message, I'm returning a console.log. So how do I test this?
check this https://node-tap.org/docs/api/snapshot-testing/
it should be able to solve your problem