0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

StateNotifierのMock方法

0
Posted at

課題

riverpodを使った開発で、テストコードを書くとき、StateNotifierのMockをなかなかうまくいかない。
build runnerで自動生成のmockだと、addListnerのstubが見つからないエラーが出る。

色々調べて、ようやく正しい書き方見つかったので、ここにメモ。

書き方

reference: https://github.com/rrousselGit/riverpod/discussions/1398
結局作成者本人の情報が一番正確、当たり前だけど。

class MockedNotifier extends StateNotifier<Model> with Mock implements MyNotifier {
  MockedNotifier(Model model): super(model);
}

感想

なぜこの書き方がうまくいくのかはわかっていない。
おそらく、with Mockを紐解けばわかるはず。
ちなみに、今まではextends Mock implements MyNotifierで書いたのだが、stateをうまく捉えられない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?