From 9d1243dd9781fa0452fa6660ed83a9d4b8588757 Mon Sep 17 00:00:00 2001 From: Hexah Date: Thu, 20 Feb 2020 20:54:21 +0100 Subject: [PATCH] Add tests --- pubspec.yaml | 3 ++- test/test.dart | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/test.dart diff --git a/pubspec.yaml b/pubspec.yaml index 761cad3..831153a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,4 +12,5 @@ dependencies: dev_dependencies: effective_dart: ^1.2.1 - dart_console: ^0.5.0 \ No newline at end of file + dart_console: ^0.5.0 + test: ^1.12.0 \ No newline at end of file diff --git a/test/test.dart b/test/test.dart new file mode 100644 index 0000000..a979cb4 --- /dev/null +++ b/test/test.dart @@ -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 +}