Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Mar 30, 2023
1 parent 6c84bf3 commit d94ebc7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/results_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,34 @@ Future<void> main([List<String>? args]) async {
if (count > 1) fail('Should only receive one event');
}
});

test('RealmResults.isValid', () {
final config = Configuration.local([Team.schema, Person.schema]);
final realm = getRealm(config);

final alice = Person('Alice');
final bob = Person('Bob');
final carol = Person('Carol');
final dan = Person('Dan');

final team = realm.write(() {
return realm.add(Team('Class of 92', players: [alice, bob, carol, dan]));
});

final players = team.players;
final playersAsResults = team.players.asResults();

expect(players.isValid, isTrue);
expect(playersAsResults.isValid, isTrue);
expect(playersAsResults, [alice, bob, carol, dan]);

realm.write(() => realm.delete(team));

expect(team.isValid, isFalse); // dead object
expect(players.isValid, isFalse); // parent is dead
expect(() => players.isEmpty, throwsException);
expect(playersAsResults.isValid, isFalse);
expect(() => playersAsResults, throwsException);
expect(() => playersAsResults.freeze(), throwsException);
});
}

0 comments on commit d94ebc7

Please sign in to comment.