[flutter_test] new WidgetTester API based on finder objects (#3288)

This commit is contained in:
Yegor
2016-04-13 23:40:15 -07:00
parent a5a34d9704
commit f3a4f722c4
67 changed files with 1671 additions and 1122 deletions

View File

@@ -0,0 +1,62 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:test/test.dart';
void main() {
group('hasWidget', () {
test('succeeds', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Text('foo'));
expect(tester, hasWidget(find.text('foo')));
});
});
test('fails with a descriptive message', () {
testWidgets((WidgetTester tester) {
TestFailure failure;
try {
expect(tester, hasWidget(find.text('foo')));
} catch(e) {
failure = e;
}
expect(failure, isNotNull);
String message = failure.message;
expect(message, contains('Expected: widget with text "foo" exists in the element tree'));
expect(message, contains("Actual: <Instance of 'WidgetTester'>"));
expect(message, contains('Which: Does not contain widget with text "foo"'));
});
});
});
group('doesNotHaveWidget', () {
test('succeeds', () {
testWidgets((WidgetTester tester) {
expect(tester, doesNotHaveWidget(find.text('foo')));
});
});
test('fails with a descriptive message', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Text('foo'));
TestFailure failure;
try {
expect(tester, doesNotHaveWidget(find.text('foo')));
} catch(e) {
failure = e;
}
expect(failure, isNotNull);
String message = failure.message;
expect(message, contains('Expected: widget with text "foo" does not exist in the element tree'));
expect(message, contains("Actual: <Instance of 'WidgetTester'>"));
expect(message, contains('Which: Contains widget with text "foo"'));
});
});
});
}