flutter_jest_style 1.0.0
flutter_jest_style: ^1.0.0 copied to clipboard
Jest-like testing for Flutter/Dart: snapshot matchers, mock helpers, watch-mode CLI, and golden test utilities in one import.
example/flutter_jest_style_example.dart
// ignore_for_file: unused_local_variable
import 'package:flutter_jest_style/flutter_jest_style.dart';
void main() {
// ── Snapshot testing ────────────────────────────────────
test('user data matches snapshot', () {
final user = {'name': 'Alice', 'age': 30};
expect(user, toMatchSnapshot('user_data'));
});
// ── Mock functions (jest.fn style) ─────────────────────
test('mock function returns stubbed value', () {
final myFn = fn<int>();
mockReturnValue(myFn, 42);
expect(myFn(), equals(42));
verify(() => myFn()).called(1);
});
test('mock with implementation', () {
final counter = fn<int>();
var n = 0;
mockImplementation(counter, () => ++n);
expect(counter(), 1);
expect(counter(), 2);
});
// ── Single-argument mock ──────────────────────────────
test('fn1 mock with argument', () {
final handler = fn1<String, int>();
when(() => handler(any())).thenReturn('ok');
expect(handler(5), equals('ok'));
verify(() => handler(5)).called(1);
});
}