我正在测试下面的函数shopify.formatRequestUrl
,并且每次我都期望函数的输出将是相同的。有没有办法让这更干?
expect(shopify.formatRequestUrl("shop"))
.equal("https://"+settings.shop+"/admin/shop.json")
expect(shopify.formatRequestUrl("/shop"))
.equal("https://"+settings.shop+"/admin/shop.json")
expect(shopify.formatRequestUrl("/shop/"))
.equal("https://"+settings.shop+"/admin/shop.json")
expect(shopify.formatRequestUrl("shop.json"))
.equal("https://"+settings.shop+"/admin/shop.json")
expect(shopify.formatRequestUrl("/admin/shop"))
.equal("https://"+settings.shop+"/admin/shop.json")
expect(shopify.formatRequestUrl("/admin/shop.json"))
.equal("https://"+settings.shop+"/admin/shop.json")
像这样: psudo code
expectAll[
shopify.formatRequestUrl("shop"),
shopify.formatRequestUrl("/shop"),
shopify.formatRequestUrl("/shop/"),
shopify.formatRequestUrl("shop.json"),
shopify.formatRequestUrl("/admin/shop"),
shopify.formatRequestUrl("/admin/shop.json")
]
.equal("https://"+settings.shop+"/admin/shop.json")
这样的事情是否存在?
答案 0 :(得分:0)
使用下划线和循环遍历所有参数的对象。
_.each([
"shop",
"/shop",
"/shop/",
"shop/",
"shop.json",
"/shop.json",
"/shop.json/",
"shop.json/",
"/admin/shop",
"/admin/shop/",
"/admin/shop.json",
"/admin/shop.json/",
"admin/shop.json/",
], function(result){
expect(shopify.formatRequestUrl(result))
.equal("https://"+settings.shop+"/admin/shop.json")
})