fluent_assertions 0.5.1 copy "fluent_assertions: ^0.5.1" to clipboard
fluent_assertions: ^0.5.1 copied to clipboard

A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests.

The Fluent Assertions library written in Dart.

It uses Dart's Extension Functions to provide a fluent wrapper around test assertions.

Usage #

Basic Assertions

These assertions are available for all objects.

Equality
'Hello'.shouldBeEqualTo('Hello');
'Hello'.shouldNotBeEqualTo('Word');
Reference equality
final me = Person(name: 'Karol');
final someoneElse = Person(name: 'Karol');
me.shouldBe(me);
me.shouldNotBe(someoneElse);
Subtypes
const num numberOfGirlsIAttract = 0;
numberOfGirlsIAttract.shouldBeInstanceOf<int>();
numberOfGirlsIAttract.shouldNotBeInstanceOf<double>();
Nullability
const hello = 'Hello';
hello.shouldNotBeNull();
const hello = null;
hello.shouldBeNull();
Booleans
const hasChildren = true;
hasChildren.shouldBeTrue();
hasChildren.shouldNotBeFalse();
const hasChildren = false;
hasChildren.shouldBeFalse();
hasChildren.shouldNotBeTrue();

Numerical Assertions

2.shouldBeGreaterOrEqualTo(2);
2.shouldBeGreaterThan(1);
2.shouldBeLessOrEqualTo(2);
1.shouldBeLessThan(2);
1.shouldBePositive();
1.shouldNotBeNegative();
(-1).shouldBeNegative();
(-1).shouldNotBePositive();
0.shouldBeZero();
1.shouldNotBeZero();
0.999.shouldBeNear(1, delta: 0.01);
0.shouldNotBeInRange(lowerBound: 1, upperBound: 6);
1.shouldBeInRange(lowerBound: 1, upperBound: 6);

String Assertions

'Flutter'.shouldBeEqualToIgnoringCase('FLUTTER');
'Flutter'.shouldNotBeEqualToIgnoringCase('Xamarin');
'Flutter rules'.shouldStartWith('Flutter');
'Flutter rules'.shouldNotStartWith('Xamarin');
'Flutter rules'.shouldStartWithIgnoringCase('FLUTTER');
'Flutter rules'.shouldNotStartWithIgnoringCase('Xamarin');
'I love Flutter'.shouldEndWith('Flutter');
'I love Flutter'.shouldNotEndWith('Xamarin');
'I love Flutter'.shouldEndWithIgnoringCase('flutter');
'I love Flutter'.shouldNotEndWithIgnoringCase('xamarin');
'I love Flutter'.shouldContain('love');
'I love Flutter'.shouldNotContain('hate');
'I love Flutter'.shouldContainIgnoringCase('LOVE');
'I love Flutter'.shouldNotContainIgnoringCase('HATE');
'I love Flutter'.shouldContainAll(['Flutter', 'love']);
'I love Flutter'.shouldContainAllIgnoringCase(['flutter', 'love']);
'I love Flutter'.shouldContainAllInOrder(['love', 'Flutter']);
'I love Flutter'.shouldContainAllInOrderIgnoringCase(['Love', 'Flutter']);
'12345'.shouldMatch(r'\d');
'Hello'.shouldNotMatch(r'\d');
''.shouldBeEmpty()
'name'.shouldNotBeEmpty()
''.shouldBeNullOrEmpty()
'name'.shouldNotBeNullOrEmpty()
' '.shouldBeBlank()
'name'.shouldNotBeBlank()
' '.shouldBeNullOrBlank()
'name'.shouldNotBeNullOrBlank()

Iterable Assertions

['Flutter', 'React Native', 'Jetpack Compose'].shouldContain('Flutter');
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainIgnoringCase('flutter');
['Flutter', 'React Native', 'Jetpack Compose'].shouldNotContain('Vue');
['Flutter', 'React Native', 'Jetpack Compose'].shouldNotContainIgnoringCase('vue');
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAny(['Flutter', 'Vue']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAnyIgnoringCase(['react native']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainNone(['Angular', 'Vue'])
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainNoneIgnoringCase(['angular', 'vue']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAll(['Jetpack Compose', 'React Native']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAllIgnoringCase(['jetpack compose', 'react native']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAllInOrder(['Flutter', 'React Native']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAllInOrderIgnoringCase(['flutter', 'react native']);
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAllThat((framework) => framework.startsWith(RegExp('[A-Z]')));
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainAnyThat((framework) => framework.contains('React'));
['Flutter', 'React Native', 'Jetpack Compose'].shouldContainNoneThat((framework) => framework.isEmpty);

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

4
likes
160
points
1.35k
downloads

Publisher

verified publisherklisiewicz.dev

Weekly Downloads

A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

test

More

Packages that depend on fluent_assertions