我不明白测试覆盖率如何处理此.catch()分支:
newUser.save()
.then((savedUser) => {
res.json(savedUser);
})
.catch(
(e) => {
if (e.name === 'ValidationError' && e.errors.username.kind === 'unique') {
res.status(409);
res.json({ error: { message: 'Existing user', field: e.errors.username.path, value: e.errors.username.value } });
} else {
/* istanbul ignore next */
next(e);
}
});
我正在测试第一个块:
if(e.name ===' ValidationError'&& e.errors.username.kind ===' unique'){...)
并且我没有测试第二个其他块,所以我添加了一个忽略的下一个声明:
其他{ / * istanbul忽略下一个* / 下一个(E); }
代码覆盖率报告第58行(如果......)为未覆盖..
| % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-|----------|----------|----------|----------|----------------|
| 100 | 93.75 | 100 | 100 | 58 |
但是以下测试正确执行,涵盖了这一行......
describe('# POST /api/v1/users', () => {
it('should NOT create a duplicated user', () => {
return request(app)
.post('/api/v1/users')
.set('Authorization', superAdminJwtToken)
.send(newUser)
.expect(httpStatus.CONFLICT)
.then((res) => {
expect(res.body.error.message).to.equal('Existing user');
expect(res.body.error.field).to.equal('username');
expect(res.body.error.value).to.equal(newUser.username);
});
});
});
答案 0 :(得分:0)
解决方案是插入
//UIImageView
@IBOutlet weak var BlurBackgroundImage: UIImageView!
//Code for Pass Image (I Watched from Youtube Tutorial)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let parsetoAnotherViews = segue.destinationViewController as! Schedule_FEED;
parsetoAnotherViews.RecieveBackground = BlurBackgroundImage.image;
let parsetoAnotherViews2 = segue.destinationViewController as! FEEDNOW_FEED;
parsetoAnotherViews2.RecieveBackground = BlurBackgroundImage.image;
}
如下
/* istanbul ignore else */
然后代码覆盖率输出为100%
| %Stmts | %Branch | %Funcs | %行|未覆盖的行| - | ---------- | ---------- | ---------- | ---------- | ---- ------------ | | 100 | 100 | 100 | 100 | 100 |