【发布时间】:2019-11-10 00:13:05
【问题描述】:
是否可以在.each 的name 部分访问对象的键?
let accounts =
[
{
details:
{
company_name:
"company_name",
email,
password:
"asdf",
},
find:
[
"_id",
"company_name",
"email",
"type",
],
type:
"creator"
},
{
details:
{
email,
first_name:
"first_name",
last_name:
"last_name",
password:
"asdf",
},
find:
[
"_id",
"email",
"first_name",
"last_name",
"type",
],
type:
"user"
},
]
describe.each(accounts)(
"%s", // <-- access the 'type' key, e.g. account.type
function (account)
{
// test code
}
)
【问题讨论】:
-
你是什么意思,“对象的密钥”?一个对象包含键。你是说索引吗?
-
@JackBashford 试图访问对象中的
type -
哦。所以第一次迭代是
creator,第二次迭代是user。对吗? -
@JackBashford 是的
-
因为
describe.each使用util.format生成名称,所以我看不到实现目标的方法。util.formatdoes not provide a way 访问特定属性
标签: javascript arrays object ecmascript-6 jestjs