New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support/create link test #2430
Support/create link test #2430
Conversation
src/test/models/shareLink.test.js
Outdated
|
||
test('share link is found, but it does not have Page', async() => { | ||
|
||
shareLink.populate = jest.fn(() => { return { _id: 'somePageId' } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このテストの shareLink
という変数名はちょっとピンとこないので、 findOneResult
とかにした方がいいかな。
|
||
const res = { | ||
render: (page) => { return page }, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
うーん、改めて実装のコードを見たけどちょっと物足りないな。
この res は mock 化して、 res.render
がちゃんと呼ばれたことを expect する
|
||
expect(shareLink.populate).toHaveBeenCalled(); | ||
expect(response).toEqual('layout-growi/shared_page'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return res.render(view, renderVars);
が呼ばれ、かつ第二引数に値が入ることを expect しないといけない。
renderVars 生成部分をどの程度 mock 化するか、addRendarVarsForPage
が呼ばれたかどうかまで確かめるかは気力次第(慣れるまでは結構大変だと思うので)
No description provided.