-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(luthor): Add tests for map validator
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:luthor/luthor.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('should return true when value is a map', () { | ||
final result = l.map().validateValue({}); | ||
|
||
switch (result) { | ||
case SingleValidationSuccess(data: _): | ||
expect(result.data, {}); | ||
case SingleValidationError(data: _, errors: _): | ||
fail('should not have errors'); | ||
} | ||
}); | ||
|
||
test('should return false when value is not a map', () { | ||
final result = l.map().validateValue('a'); | ||
|
||
switch (result) { | ||
case SingleValidationSuccess(data: _): | ||
fail('should not be a success'); | ||
case SingleValidationError(data: _, errors: final errors): | ||
expect(errors, ['value must be a Map']); | ||
} | ||
}); | ||
|
||
test('should return true when value is null', () { | ||
final result = l.map().validateValue(null); | ||
|
||
switch (result) { | ||
case SingleValidationSuccess(data: _): | ||
expect(result.data, isNull); | ||
case SingleValidationError(data: _, errors: _): | ||
fail('should not have errors'); | ||
} | ||
}); | ||
|
||
test('should return false if the value is null with required()', () { | ||
final result = l.required().map().validateValue(null); | ||
|
||
switch (result) { | ||
case SingleValidationSuccess(data: _): | ||
fail('should not be a success'); | ||
case SingleValidationError(data: _, errors: final errors): | ||
expect(errors, ['value is required']); | ||
} | ||
}); | ||
} |