Last active
April 20, 2020 09:39
-
-
Save TetsuFe/fde9f8356e730f4bce5ec9b23d2dceb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:mockito/mockito.dart'; | |
import 'notice.dart'; | |
import 'notice_api.dart'; | |
import 'notice_bloc.dart'; | |
class MockNoticeApi extends Mock implements NoticeApi {} | |
void main() { | |
group('notice', () { | |
test('Bloc fetches my notice list', () async { | |
final noticeList = [ | |
Notice.fromJson( | |
{ | |
'id': 1, | |
'body': 'お知らせです', | |
'imageUrl': 'https://pbs.twimg.com/profile_images/1173564926905831424/XqIV7z5I_400x400.jpg', | |
'link': '/chat/1', | |
'created_at': '2020-04-18T22:38:50.018298+09:00', | |
}, | |
) | |
]; | |
final mockNoticeApi = MockNoticeApi(); | |
when(mockNoticeApi.fetchMyNoticeList()) | |
.thenAnswer((_) => Future.value(noticeList)); | |
final bloc = NoticeBloc(noticeApi: mockNoticeApi); | |
expect(bloc.notices.value, null); | |
expect( | |
bloc.notices, | |
emitsInOrder([emits((val) => val == null), emits((val) => val == noticeList)]), | |
); | |
bloc.fetchMyNoticeList(); | |
expect( | |
bloc.notices, | |
emitsInOrder([ | |
emits((val) => val == null), | |
emits((val) => val == noticeList), | |
emits((val) => val == noticeList) | |
]), | |
); | |
bloc.fetchMyNoticeList(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment