Skip to content

Commit

Permalink
refactor(flutter_bloc_with_stream): improve test descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Jul 28, 2024
1 parent 8f8b66b commit cf42796
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/flutter_bloc_with_stream/test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'package:flutter_bloc_with_stream/main.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('TickerApp', () {
group(TickerApp, () {
testWidgets('is a MaterialApp', (tester) async {
expect(TickerApp(), isA<MaterialApp>());
});

testWidgets('renders TickerPage', (tester) async {
testWidgets('renders $TickerPage', (tester) async {
await tester.pumpWidget(TickerApp());
expect(find.byType(TickerPage), findsOneWidget);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import 'package:flutter_bloc_with_stream/ticker/ticker.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockTicker extends Mock implements Ticker {}
class _MockTicker extends Mock implements Ticker {}

void main() {
group('TickerBloc', () {
group(TickerBloc, () {
late Ticker ticker;

setUp(() {
ticker = MockTicker();
ticker = _MockTicker();
when(ticker.tick).thenAnswer(
(_) => Stream<int>.fromIterable([1, 2, 3]),
);
});

test('initial state is TickerInitial', () {
test('initial state is $TickerInitial', () {
expect(TickerBloc(ticker).state, TickerInitial());
});

Expand All @@ -30,7 +30,7 @@ void main() {
);

blocTest<TickerBloc, TickerState>(
'emits TickerTickSuccess from 1 to 3',
'emits $TickerTickSuccess from 1 to 3',
build: () => TickerBloc(ticker),
act: (bloc) => bloc.add(TickerStarted()),
expect: () => <TickerState>[
Expand All @@ -42,7 +42,7 @@ void main() {
);

blocTest<TickerBloc, TickerState>(
'emits TickerTickSuccess '
'emits $TickerTickSuccess '
'from 1 to 3 and cancels previous subscription',
build: () => TickerBloc(ticker),
act: (bloc) => bloc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:flutter_bloc_with_stream/bloc/ticker_bloc.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('TickerEvent', () {
group('TickerStarted', () {
group(TickerEvent, () {
group(TickerStarted, () {
test('supports value comparison', () {
expect(TickerStarted(), equals(TickerStarted()));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import 'package:flutter_bloc_with_stream/bloc/ticker_bloc.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('TickerState', () {
group('TickerInitial', () {
group(TickerState, () {
group(TickerInitial, () {
test('supports value comparison', () {
expect(TickerInitial(), TickerInitial());
});
});

group('TickerTickSuccess', () {
group(TickerTickSuccess, () {
test('supports value comparison', () {
expect(TickerTickSuccess(1), TickerTickSuccess(1));
expect(
Expand All @@ -21,7 +21,7 @@ void main() {
});
});

group('TickerComplete', () {
group(TickerComplete, () {
test('supports value comparison', () {
expect(TickerComplete(), equals(TickerComplete()));
});
Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_bloc_with_stream/test/ticker_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter_bloc_with_stream/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockTickerBloc extends MockBloc<TickerEvent, TickerState>
class _MockTickerBloc extends MockBloc<TickerEvent, TickerState>
implements TickerBloc {}

extension on WidgetTester {
Expand All @@ -25,12 +25,12 @@ void main() {
late TickerBloc tickerBloc;

setUp(() {
tickerBloc = MockTickerBloc();
tickerBloc = _MockTickerBloc();
});

tearDown(() => reset(tickerBloc));

group('TickerPage', () {
group(TickerPage, () {
testWidgets('renders initial state', (tester) async {
when(() => tickerBloc.state).thenReturn(TickerInitial());
await tester.pumpTickerPage(tickerBloc);
Expand Down

0 comments on commit cf42796

Please sign in to comment.