Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

單元測試錯誤排解 (1)

Posted at 2016-07-01 Sails Supertest Unit Test 

今天踩到一個自己種的雷,使用 res.ok 的時候少了一個 { },但其實如果你只傳一個物件,物件本身外層本來就有 { } 不需要再多一個 { },但如果是傳基本型別,就一定得要有 { } 存在,缺少 { } 的時候,單元測試會抓到 res.statusCode == 1,還蠻神奇的。

主程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
userlikes: async(req, res) => {
const gamelistId = req.params.gamelistId;
try {
let user = UserService.getLoginUser(req);
let likeCount = await UserLikeService.like(user.id, gamelistId);
//return res.ok(
// likeCount
//);
return res.ok({
likeCount
});
} catch (e) {
return res.serverError(e);
}
}

測試程式

1
2
3
4
5
6
7
8
9
10
11
it('post /api/gamelists/:gamelistId/userlikes', async(done) => {
request(sails.hooks.http.app)
.post(`/api/gamelists/${gamelistId}/userlikes`)
.end((err, res) => {
let result = res.body;
// res.statusCode.should.be.equal(1);
res.statusCode.should.be.equal(200);
result.likeCount.should.be.equal(1);
done(err);
});
});

Share 

 Previous post: Sequelize belongsToMany Next post: WebdriverIO VS Protractor 架構(2) 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo