Browse Source

neon: test result

pull/395/head
Nikolas Rimikis 1 year ago
parent
commit
041078512e
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 84
      packages/neon/neon/test/result_test.dart

84
packages/neon/neon/test/result_test.dart

@ -0,0 +1,84 @@
import 'package:neon/neon.dart';
import 'package:test/test.dart';
void main() {
group('Result', () {
test('Equality', () {
const data = 'someData';
const a = Result(
data,
null,
isLoading: true,
isCached: false,
);
const b = Result(
data,
null,
isLoading: true,
isCached: true,
);
expect(a, equals(a), reason: 'identical');
expect(a, equals(b), reason: 'ignore cached state in equality');
expect(a.hashCode, equals(a.hashCode), reason: 'identical');
expect(a.hashCode, isNot(equals(b.hashCode)), reason: 'hashcode should respect the cached state');
});
test('Transform to loading', () {
const data = 'someData';
final a = Result.success(data);
const b = Result(
data,
null,
isLoading: true,
isCached: false,
);
expect(a, isNot(equals(b)));
expect(a.asLoading(), equals(b));
});
test('data check', () {
const data = 'someData';
final a = Result.loading();
final b = Result.success(data);
const c = Result(
data,
null,
isLoading: false,
isCached: true,
);
expect(a.hasData, false);
expect(b.hasData, true);
expect(() => a.requireData, throwsStateError);
expect(b.requireData, equals(data));
expect(b.hasUncachedData, true);
expect(c.hasUncachedData, false);
});
test('error check', () {
const error = 'someError';
final a = Result.error(error);
expect(a.hasError, true);
});
test('transform', () {
const data = 1;
final a = Result.success(data);
String transformer(final int data) => data.toString();
expect(a.transform(transformer), equals(Result.success(data.toString())));
});
});
}
Loading…
Cancel
Save