Skip to content

shinayser/mocktailx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mocktailx

A set of utility functions for mocktail apis.

Usage

First import mocktailx to your pubspec:

mocktailx: ^latest version here

Note that this library is a container for mocktail, so you don't need to import mocktail.
And don't forget to fix your imports:

import 'package:mocktailx/mocktailx.dart';  

Features

thenAnswerWithVoid

// Instead of doing:  
when(repo.futureVoidFunction).thenAnswer((invocation) async {});  
// You can just:  
when(repo.futureVoidFunction).thenAnswerWithVoid();   

thenAnswerWith(T)

// Instead of doing:  
when(repo.futureIntFunction).thenAnswer((invocation) async => 10);  
// You can just:  
when(repo.futureIntFunction).thenAnswerWith(10);  

thenAnswerInOrder(List<Answer>)

// Instead of doing:  
final List<Future<int> Function(Invocation)> answers = [
(_) async => 6,
(_) async => 7,
(_) async => 99,
]; 
when(() => repo.asyncInteger()).thenAnswer((invocation) => answers.removeAt(0)(invocation));
// You can just:  
when(() => repo.asyncInteger()).thenAnswerInOrder([
    (invocation) async => 6,
    (_) async => 7,
    (_) async => 99,
]);

thenEmit(List)

// Instead of doing:  
when(repo.streamValue).thenAnswer((invocation) => Stream.fromIterable([1,2,3,4,5]));  
// You can just:  
when(repo.streamValue).thenEmit([1,2,3,4,5]);  

thenReturnWithVoid

// Instead of doing:  
when(repo.voidFunction).thenReturn(null);  
// You can just:  
when(repo.voidFunction).thenReturnWithVoid();   

thenReturnInOrder(List)

// Instead of doing:  
when(() => repo.addOne(1)).thenReturn(6);
when(() => repo.addOne(2)).thenReturn(7);
when(() => repo.addOne(3)).thenReturn(99);

// You can just:  
when(() => repo.addOne(any())).thenReturnInOrder([6, 7, 99]);
// Instead of doing:  
final answers = [6, 7, 99];
when(() => repo.addOne(1)).thenAnswer((invocation) => answers.removeAt(0));

// You can just:  
when(() => repo.addOne(1)).thenReturnInOrder([6, 7, 99]);

About

A set of utility methods over mocktail library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages