我正在尝试为一个REST API编写测试,它可以返回两个http状态码中的一个,我认为这两个状态码都是正确的。
出于某种原因,我使用的是Frisby2,这个库非常简单,你甚至不需要文档就能使用它!
总之,在Frisby自己的单元测试中,它与regex进行了比较:
it('expectHeader should match with regex', function(doneFn) {
mocks.use(['getUser1']);
frisby.fetch(testHost + '/users/1')
.expect('header', 'Content-Type', /json/)
.done(doneFn);
});太棒了!所以我将使用这一点:
frisby.fetch('/rest/endpoint', {
method: 'POST',
body: form
})
.expect('status', /201|429/)哦,亲爱的
assert.strictEqual(received, expected)
Expected value to be (operator: ===):
/201|429/
Received:
429
Message:
HTTP status /201|429/ !== 429
Difference:
Comparing two different types of values. Expected regexp but received number.我做错了什么?
发布于 2018-04-09 11:55:27
看起来你可以退回到Jasmine来做这类事情:
frisby.fetch('/rest/endpoint', {
method: 'POST',
body: form
})
.then(function (res) {
expect(res.status === 201 || res.status === 429).toBe(true);
})https://stackoverflow.com/questions/49724823
复制相似问题