Skip to content

Commit

Permalink
fix: (#55) Uncaught SyntaxError: Unexpected token ' in JSON 에러 해결
Browse files Browse the repository at this point in the history
handler 함수들의 반환 값에 ctx.json 추가
  • Loading branch information
inyeong-kang committed Jul 18, 2023
1 parent 729e922 commit 238af20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions frontend/src/components/PostForm/PostForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Meta } from '@storybook/react';

import { PostRequest } from '@type/post';

import { useCreatePost } from '@hooks/query/post/useCreatePost';
import { useEditPost } from '@hooks/query/post/useEditPost';

import PostForm from '.';

const meta: Meta<typeof PostForm> = {
Expand All @@ -23,17 +26,20 @@ const MOCK_DATA: PostRequest = {
};

export const NewPost = () => {
const { mutate } = useCreatePost();
return (
<>
<PostForm mutate={() => {}} />
<PostForm mutate={mutate} />
</>
);
};

export const OldPost = () => {
const examplePostId = 1;
const { mutate } = useEditPost(examplePostId);
return (
<>
<PostForm data={MOCK_DATA} mutate={() => {}} />
<PostForm data={MOCK_DATA} mutate={mutate} />
</>
);
};
12 changes: 10 additions & 2 deletions frontend/src/mocks/jero/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ export const createEditPostTest = [
rest.post('/posts', (req, res, ctx) => {
window.console.log('게시글 작성 완료', req.body);

return res(ctx.status(201));
return res(
ctx.delay(1000),
ctx.status(201),
ctx.json({ message: '게시글이 성공적으로 생성되었습니다!!' })
);
}),

//게시글 수정
rest.put('/posts/1', (req, res, ctx) => {
window.console.log('게시글 수정 완료', req.body);

return res(ctx.status(200));
return res(
ctx.delay(1000),
ctx.status(201),
ctx.json({ message: '게시글이 성공적으로 수정되었습니다!!' })
);
}),
];

0 comments on commit 238af20

Please sign in to comment.