契约提供者验证中的调试

问题描述 投票:0回答:1

我目前正在尝试验证契约,但在提供者测试中,响应体不匹配。

我得到以下错误信息

JSON::ParserError:757: unexpected token at 'null'

我通过邮递员收到了正确的请求。有什么方法可以让我检查发出的请求和收到的响应?

我试过设置 logLevelDebug但它没有提供预期的数据。

if("validates the expectations of api", async function () {
    let opts = {
        provider: "consumer",
        logLevel: "DEBUG",
        verbose: true,
        enablePending: true,
        providerBaseUrl: "http://10.54.12.223:8083",
        pactUrls: [
          path.resolve(process.cwd(), "./pacts/<name>.json")
        ],
        providerVersion: "1.0.0"
    }

    return new Verifier(opts).verifyProvider().then(output => {
        console.log("Verification complete!");
    }

})
javascript pact
1个回答
0
投票

如果没有响应体,就很难诊断。pact文件可能有用,但我怀疑是响应体不正确。很可能是你的代码没有返回有效的JSON。请看类似的错误 https:/github.compact-foundationpact-netissues139.

如果响应类型是 application/json 而body不是有效的JSON。

你使用的是什么版本的Pact Node?在旧版本的Pact中存在一个问题,不允许使用顶层的字符串或 null (见上述问题)。

© www.soinside.com 2019 - 2024. All rights reserved.