簡體   English   中英

使用 tap 來測試 console.log 的輸出

[英]Use tap to test the output of a console.log

我有一個非常基本的腳本,我希望能夠使用 node-tap 添加覆蓋范圍:

const chalk = require('chalk')

module.exports = skip = type => console.log(chalk.blue(`Skipping generation of ${type} due to user selection`))

它所做的只是向用戶顯示一條 console.log 消息(它是一個命令行應用程序)。

我已經為它編寫了以下點擊測試:

// 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()
})

但顯然這失敗了,因為我沒有返回該消息,我返回的是 console.log。 那么我該如何測試呢?

檢查這個https://node-tap.org/docs/api/snapshot-testing/

它應該能夠解決你的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM