Skip to content
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

Merged

Conversation

itizawa
Copy link
Contributor

@itizawa itizawa commented Jun 21, 2020

No description provided.

@itizawa itizawa self-assigned this Jun 21, 2020

test('share link is found, but it does not have Page', async() => {

shareLink.populate = jest.fn(() => { return { _id: 'somePageId' } });
Copy link
Member

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 },
};
Copy link
Member

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');
});
Copy link
Member

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 が呼ばれたかどうかまで確かめるかは気力次第(慣れるまでは結構大変だと思うので)

@yuki-takei yuki-takei merged commit 1cf8999 into support/share-link-for-outside-for-merge Jun 23, 2020
@yuki-takei yuki-takei deleted the support/create-link-test branch June 23, 2020 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants