Skip to content

Instantly share code, notes, and snippets.

@daniel-v
Last active January 21, 2021 07:34
Show Gist options
  • Save daniel-v/01bc73a2732e6f80e76a5f92b025749c to your computer and use it in GitHub Desktop.
Save daniel-v/01bc73a2732e6f80e76a5f92b025749c to your computer and use it in GitHub Desktop.
Dead code seems to work around some compiler issue?
global_options:
build_web_compilers|dart_source_cleanup:
release_options:
enabled: false
build_web_compilers|dart2js_archive_extractor:
release_options:
filter_outputs: false
targets:
build_test_13_sourcemap:
builders:
angular:angular:
generate_for:
include:
- web/main.dart
- test/**
build_web_compilers:entrypoint:
generate_for:
include:
- web/main.dart
- test/**
options:
compiler: dartdevc
release_options:
compiler: dart2js
dart2js_args:
- -O1
@TestOn('browser')
library aync_pipe_test;
import 'dart:async';
import 'package:angular/angular.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';
import 'app_test.template.dart' as self;
void main() {
tearDown(() => disposeAnyRunningTest());
test('mock emits value just as a real Stream implementation would', () async {
final stream = MockBloc();
await expectLater(stream, emits(999));
});
test('this really should not fail', () async {
final testBed = NgTestBed.forComponent<MockAsyncTest>(self.MockAsyncTestNgFactory);
final fixture = await testBed.create();
expect(fixture.rootElement.outerHtml, contains('999'));
});
return;
test('dead code with reference to another component fixes previous test', () {
NgTestBed.forComponent<ValueAsyncTest>(self.ValueAsyncTestNgFactory);
});
}
@Component(
selector: 'mock-async-test',
template: '''MockStream:{{ mockStream | async }}''',
pipes: [AsyncPipe],
)
class MockAsyncTest {
final Stream<int> mockStream = MockBloc();
}
@Component(
selector: 'value-async-test',
template: '''ValueStream:{{valueStream | async}}''',
pipes: [AsyncPipe],
)
class ValueAsyncTest {
final valueStream = Future.value(777);
}
class MockBloc implements Stream<int> {
@override
dynamic noSuchMethod(Invocation invocation) {
// this is more or less how mockito works
switch (invocation.memberName) {
case #listen:
return Stream.value(999).listen(
invocation.positionalArguments.first,
onError: invocation.namedArguments['onError'],
);
case #isBroadcast:
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment