【问题标题】:printf each with an Object node #8774printf 每个都有一个 Object 节点 #8774
【发布时间】:2019-12-10 15:28:26
【问题描述】:
// Returns Testing [Object object]
describe.skip.each([[{foo: 'abc'}], [{foo: 'bca'}]])('Testing %s', ...
// Returns Testing {foo: 'abc'}
describe.skip.each([[{foo: 'abc'}], [{foo: 'bca'}]])('Testing %o', ...

有没有可能做类似...

// Expect Testing abc
describe.skip.each([[{foo: 'abc'}], [{foo: 'bca'}]])('Testing %o.foo', ...

【问题讨论】:

    标签: javascript printf jestjs


    【解决方案1】:

    我认为使用该 API 是不可能的,但使用 second API it is

    describe.each`
        column
        ${{ foo: 'abc' }}
        ${{ foo: 'bca' }}
        `
        ('Testing $column.foo', ({ column }) => {
            ...
        })
    

    更新

    Sadly you cannot build a template literal programmatically, here's how tagged template literals work 需要${expresion} 来标识您要传递的数据。

    【讨论】:

    • 有效!但是当我使用每个字符串中的列时才有效。是否可以制作一个我可以用于其他测试的常量?
    • describe.each` tests ${testCases} ` testCases 是我的列行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 2016-05-18
    • 1970-01-01
    相关资源
    最近更新 更多