Slide 31
Slide 31 text
MSW
を使ったストーリー①
export const SearchSubject: ComponentStoryObj = {
args: {
onSubmit: () => undefined,
},
play: async () => {
const input = screen.getByLabelText('
科目名や先生名を入力するテキストフィールド');
await userEvent.type(input, '
英語', {
delay: 200,
});
},
parameters: {
msw: {
handlers: [
rest.get('/teachers/suggests', (req, res, ctx) => {
return res(
ctx.json([
{
target: 'subjects',
item_id: 'english',
name: '
英語',
},
] as AutocompleteItem[]),
);
play
関数を指定すると、テキストフィールドに文字
を入力させるなどの操作ができる
userEvent.type
メソッドで「英語」という文字を200
ミリ秒遅らせて(
リアルに)
入力させる