From 5d1551218844792a7e053d967893c920996f0f48 Mon Sep 17 00:00:00 2001 From: Ashraf Kamarudin Date: Sat, 23 May 2020 07:30:04 +0800 Subject: [PATCH] feat: add test for anonymous function --- test/flutter_cache_test.dart | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/flutter_cache_test.dart b/test/flutter_cache_test.dart index ad82b5f..3800c65 100644 --- a/test/flutter_cache_test.dart +++ b/test/flutter_cache_test.dart @@ -98,8 +98,41 @@ void main() { test('It can use anonymous function', () async { + await Cache.remember('key', () { + return 'old'; + }, 5); + + expect(await Cache.remember('key', () { + return 'new'; + }), 'old'); + + await Future.delayed(const Duration(seconds: 6), (){}); + + expect(await Cache.remember('key', () { + return 'new'; + }), 'new'); + expect(await Cache.remember('string', () { return 'test'; }), 'test'); + + expect(await Cache.remember('string', () => 'test'), 'test'); + }); + + test('It will load first then fetch', () async { + + await Cache.remember('key', () { + return 'old'; + }, 5); + + expect(await Cache.remember('key', () { + return 'new'; + }), 'old'); + + await Future.delayed(const Duration(seconds: 6), (){}); + + expect(await Cache.remember('key', () { + return 'new'; + }), 'new'); }); }