Skip to content

Commit

Permalink
Merge pull request #95 from aaronlademann-wf/move-test-utils-to-over-…
Browse files Browse the repository at this point in the history
…react-test

UIP-2272 Remove test utilities that belong in over_react_test
  • Loading branch information
leviwith-wf authored Jul 28, 2017
2 parents 4a149e3 + 0091e81 commit b370c39
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 754 deletions.
41 changes: 34 additions & 7 deletions lib/src/util/validation_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,56 @@ library over_react.validation_util;

import 'dart:html';

import 'package:over_react/src/util/pretty_print.dart';
import 'package:over_react/src/util/react_wrappers.dart';
import 'package:over_react/over_react.dart';
import 'package:react/react.dart' as react;

typedef void ValidationUtilWarningCallback(String message);

/// Utility for logging validation errors or warning.
/// Utility for logging validation errors or warnings.
class ValidationUtil {

static bool WARNINGS_ENABLED = true;
static bool THROW_ON_WARNING = false;
static int WARNING_COUNT = 0;

/// Use this to log warnings to the console in dev mode only.
/// This is to be used in assert calls for dev help only so that it gets
/// compiled out for production.
///
/// Code that produces the warnings will not be included when you compile in production mode.
///
/// assert(ValidationUtil.warn('Some warning message'));
///
/// Optionally, a component or element can be passed as the second parameter
/// Optionally, a component or element can be passed as [data]
/// to provide additional information in the console.
///
/// assert(ValidationUtil.warn('Some warning message', component));
///
/// The message will be printed out to the console.
/// Assert that your component emits a warning using
/// the validation test utilities available within
/// `package:over_react_test/over_react_test.dart` like so:
///
/// group('emits a warning to the console', () {
/// setUp(startRecordingValidationWarnings);
///
/// tearDown(stopRecordingValidationWarnings);
///
/// test('when <describe something that should trigger a warning>', () {
/// // Do something that should trigger a warning
///
/// verifyValidationWarning(/* some Matcher or String */);
/// });
///
/// test('unless <describe something that should NOT trigger a warning>', () {
/// // Do something that should NOT trigger a warning
///
/// rejectValidationWarning(/* some Matcher or String */);
/// });
/// },
/// // Be sure to not run these tests in JS browsers
/// // like Chrome, Firefox, etc. since the OverReact
/// // ValidationUtil.warn() method will only produce a
/// // console warning when compiled in "dev" mode.
/// testOn: '!js'
/// );
static bool warn(String message, [dynamic data]) {
WARNING_COUNT += 1;

Expand Down Expand Up @@ -75,6 +100,8 @@ class ValidationUtil {
/// Callback for when warnings are logged.
///
/// Useful for verifying warnings in unit tests.
///
/// > See: [startRecordingValidationWarnings]
static ValidationUtilWarningCallback onWarning;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dev_dependencies:
coverage: "^0.7.2"
dart_dev: "^1.7.6"
mockito: "^0.11.0"
over_react_test: "^1.0.1"
over_react_test: "^1.1.1"
test: "^0.12.24"

transformers:
Expand Down
2 changes: 1 addition & 1 deletion test/over_react/component/abstract_transition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import 'dart:async';
import 'dart:html';

import 'package:over_react/over_react.dart';
import 'package:over_react_test/over_react_test.dart';
import 'package:test/test.dart';

import '../../test_util/test_util.dart';
import '../../wsd_test_util/validation_util_helpers.dart';

/// Main entry point for AbstractTransition testing
main() {
Expand Down
18 changes: 8 additions & 10 deletions test/over_react/component/prop_mixins_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ library prop_mixins_test;
import 'dart:collection' show MapView;

import 'package:over_react/over_react.dart';
import 'package:over_react_test/over_react_test.dart';
import 'package:test/test.dart';

import '../../wsd_test_util/prop_utils.dart';
import '../../test_util/prop_utils.dart';

main() {
group('ReactProps', () {
Expand Down Expand Up @@ -69,8 +68,7 @@ main() {
group('AriaProps', () {
test('cannot set / read values that are not its prop map', () {
var instance = new AriaPropMixinsTest({});
expect(() {instance['notThere'];},
throwsA(hasToStringValue(contains('Map does not contain this key'))));
expect(() {instance['notThere'];}, throwsArgumentError);
});

for (var propKey in const $PropKeys(AriaPropsMixin)) {
Expand All @@ -94,7 +92,7 @@ class DomPropMixinsTest extends MapView with DomPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand All @@ -112,7 +110,7 @@ class SvgPropMixinsTest extends MapView with SvgPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand All @@ -130,7 +128,7 @@ class ReactPropMixinsTest extends MapView with ReactPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand All @@ -148,7 +146,7 @@ class CssClassPropMixinsTest extends MapView with CssClassPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand All @@ -165,7 +163,7 @@ class UbiquitousPropMixinsTest extends MapView with UbiquitousDomPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand All @@ -182,7 +180,7 @@ class AriaPropMixinsTest extends MapView with AriaPropsMixin {
@override
operator [](key) {
if (!this.containsKey(key)) {
throw 'Map does not contain this key: $key';
throw new ArgumentError('Map does not contain this key: $key');
}
return super[key];
}
Expand Down
6 changes: 1 addition & 5 deletions test/over_react/component/resize_sensor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ import 'dart:html';

import 'package:platform_detect/platform_detect.dart';
import 'package:over_react/over_react.dart';
import 'package:over_react_test/over_react_test.dart';
import 'package:react/react_dom.dart' as react_dom;
import 'package:test/test.dart';

import '../../test_util/test_util.dart';
import '../../wsd_test_util/common_component_tests.dart';
import '../../wsd_test_util/validation_util_helpers.dart';
import '../../wsd_test_util/zone.dart';

void main() {
group('ResizeSensor', () {
const int defaultContainerWidth = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import 'dart:async';
import 'dart:html';

import 'package:over_react/over_react.dart' show Dom, DummyComponent, ValidationUtil;
import 'package:over_react_test/over_react_test.dart';
import 'package:over_react/src/component_declaration/component_base.dart';
import 'package:over_react/src/component_declaration/component_type_checking.dart';
import 'package:react/react_client.dart';
import 'package:test/test.dart';
import 'package:w_common/disposable.dart';

import '../../test_util/test_util.dart';
import '../../wsd_test_util/validation_util_helpers.dart';
import '../shared/map_proxy_tests.dart';

main() {
Expand Down
2 changes: 1 addition & 1 deletion test/over_react/util/dom_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ library dom_util_test;
import 'dart:html';

import 'package:over_react/over_react.dart';
import 'package:over_react_test/over_react_test.dart';
import 'package:test/test.dart';

import '../../test_util/test_util.dart';
import '../../wsd_test_util/validation_util_helpers.dart';

/// Main entry point for DomUtil testing
main() {
Expand Down
6 changes: 2 additions & 4 deletions test/over_react/util/handler_chain_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ main() {

var chained = callbackUtil.chain(a, b);

expect(() => Function.apply(chained, generateBadTypeArgs()),
throwsA(const isInstanceOf<TypeError>()));
expect(() => Function.apply(chained, generateBadTypeArgs()), throwsA(const isInstanceOf<TypeError>()));
}, testOn: 'dart-vm');
}
});
Expand Down Expand Up @@ -246,8 +245,7 @@ main() {

var chained = callbackUtil.chainFromList(functions);

expect(() => Function.apply(chained, generateBadTypeArgs()),
throwsA(const isInstanceOf<TypeError>()));
expect(() => Function.apply(chained, generateBadTypeArgs()), throwsA(const isInstanceOf<TypeError>()));
}, testOn: 'dart-vm');
}
});
Expand Down
47 changes: 0 additions & 47 deletions test/over_react/util/prop_error_test.dart

This file was deleted.

16 changes: 0 additions & 16 deletions test/over_react/util/react_wrappers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import 'package:test/test.dart';
import '../../test_util/one_level_wrapper.dart';
import '../../test_util/test_util.dart';
import '../../test_util/two_level_wrapper.dart';
import '../../wsd_test_util/test_js_component.dart';

/// Main entry point for react wrappers testing
main() {
Expand Down Expand Up @@ -383,21 +382,6 @@ main() {
});
});

group('isMounted (deprecated)', () {
test('returns true for a component that has been mounted', () {
var mountNode = new DivElement();
var renderedInstance = react_dom.render(Wrapper()(), mountNode);
expect(renderedInstance.isMounted(), isTrue);
});

test('returns false for a component that has been umounted', () {
var mountNode = new DivElement();
var renderedInstance = react_dom.render(Wrapper()(), mountNode);
react_dom.unmountComponentAtNode(mountNode);
expect(renderedInstance.isMounted(), isFalse);
});
});

test('getInstanceKey returns the key set on a ReactElement', () {
ReactElement instance = (Dom.div()..key = 'foo')();
expect(getInstanceKey(instance), equals('foo'));
Expand Down
2 changes: 1 addition & 1 deletion test/over_react/util/test_mode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:over_react/src/component_declaration/component_base.dart' as com
import 'package:over_react/src/util/test_mode.dart';
import 'package:test/test.dart';

/// Main entry point for enableTestMode and disabledTestMode testing
/// Main entry point for [enableTestMode] and [disableTestMode] testing
main() {
test('enableTestMode and disableTestMode set UiProps.testMode as expected', () {
disableTestMode();
Expand Down
2 changes: 0 additions & 2 deletions test/over_react_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import 'over_react/util/guid_util_test.dart' as guid_util_test;
import 'over_react/util/handler_chain_util_test.dart' as handler_chain_util_test;
import 'over_react/util/map_util_test.dart' as map_util_test;
import 'over_react/util/pretty_print_test.dart' as pretty_print_test;
import 'over_react/util/prop_error_test.dart' as prop_error_test;
import 'over_react/util/prop_key_util_test.dart' as prop_key_util_test;
import 'over_react/util/react_wrappers_test.dart' as react_wrappers_test;
import 'over_react/util/rem_util_test.dart' as rem_util_test;
Expand All @@ -55,7 +54,6 @@ void main() {
handler_chain_util_test.main();
map_util_test.main();
pretty_print_test.main();
prop_error_test.main();
prop_key_util_test.main();
react_wrappers_test.main();
rem_util_test.main();
Expand Down
File renamed without changes.
Empty file removed test/test_util/dom_util.dart
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions test/test_util/wrapper_component.dart

This file was deleted.

Loading

0 comments on commit b370c39

Please sign in to comment.