Add tests

This commit is contained in:
Hexah 2020-02-20 20:54:21 +01:00
parent 8b3ad83981
commit 9d1243dd97
2 changed files with 48 additions and 1 deletions

View File

@ -12,4 +12,5 @@ dependencies:
dev_dependencies:
effective_dart: ^1.2.1
dart_console: ^0.5.0
dart_console: ^0.5.0
test: ^1.12.0

46
test/test.dart Normal file
View File

@ -0,0 +1,46 @@
import 'package:test/test.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
void main() {
test('Parse valid video id', () {
var id = 'en2D_5TzXCA';
expect(YoutubeExplode.parseVideoId(id), equals('en2D_5TzXCA'));
});
test('Parse id from youtube url', () {
var url = 'https://www.youtube.com/watch?v=en2D_5TzXCA';
expect(YoutubeExplode.parseVideoId(url), equals('en2D_5TzXCA'));
});
test('Get video title', () async {
var yt = YoutubeExplode();
var video = await yt.getVideo('en2D_5TzXCA');
expect(video.title, equals('Lady Gaga - Million Reasons'));
yt.close();
});
test('Parse invalid id', () {
var id = 'aaa';
expect(YoutubeExplode.parseVideoId(id), isNull);
});
test('Get video media stream', () async {
var yt = YoutubeExplode();
expect(await yt.getVideoMediaStream('en2D_5TzXCA'), isNotNull);
yt.close();
});
test('Get video media stream with invalid id', () async {
var yt = YoutubeExplode();
var stream = yt.getVideoMediaStream('aaa').asStream();
stream.listen(neverCalled)
..onError(expectAsync1((error) {
expect(error, isArgumentError);
}))
..onDone(() {
yt.close();
});
});
// TODO: Implement more tests
}