首页 > 解决方案 > 如何在邮递员中正则表达式 Content-Disposition 标头值?

问题描述

我在我的邮递员 API 请求中添加了一些测试,我想知道如何将正则表达式添加到 Content-Disposition 标头值中,我有类似的东西,但日期是动态的,只是想使用正则表达式或做一些其他方法,任何想法?

pm.test("My test file name is downloaded successfully", function () {
    pm.response.to.have.header("Content-Disposition", "attachment; filename=Test Project_information_10_15_2021.xlsx");

标签: testingpostmanpostman-testcase

解决方案


你可以这样做:

pm.test("My test file name is downloaded successfully", () => { 
    const content = pm.response.headers.get("Content-Disposition");
    pm.expect(content).to.match(/^attachment.+xlsx$/);
});

推荐阅读