platform/packages/container/angel_container/test/has_test.dart

51 lines
1.1 KiB
Dart
Raw Normal View History

2018-08-26 22:55:21 +00:00
import 'package:angel_container/angel_container.dart';
import 'package:test/test.dart';
void main() {
2021-03-18 00:21:42 +00:00
late Container container;
2018-08-26 22:55:21 +00:00
setUp(() {
2019-10-12 13:34:15 +00:00
container = Container(const EmptyReflector())
..registerSingleton<Song>(Song(title: 'I Wish'))
2019-04-10 19:20:02 +00:00
..registerNamedSingleton('foo', 1)
2018-08-26 22:55:21 +00:00
..registerFactory<Artist>((container) {
2019-10-12 13:34:15 +00:00
return Artist(
2018-08-26 22:55:21 +00:00
name: 'Stevie Wonder',
song: container.make<Song>(),
);
});
});
2019-04-10 19:20:02 +00:00
test('hasNamed', () {
var child = container.createChild()..registerNamedSingleton('bar', 2);
expect(child.hasNamed('foo'), true);
expect(child.hasNamed('bar'), true);
expect(child.hasNamed('baz'), false);
});
2018-08-26 22:55:21 +00:00
test('has on singleton', () {
expect(container.has<Song>(), true);
});
test('has on factory', () {
expect(container.has<Artist>(), true);
});
test('false if neither', () {
expect(container.has<bool>(), false);
});
}
class Artist {
2021-03-18 00:21:42 +00:00
final String? name;
final Song? song;
2018-08-26 22:55:21 +00:00
Artist({this.name, this.song});
}
class Song {
2021-03-18 00:21:42 +00:00
final String? title;
2018-08-26 22:55:21 +00:00
Song({this.title});
}