Skip to content

Commit e63ec7b

Browse files
gnpricechrisbobbe
authored andcommitted
internal_link test: Push store setup properly inside test code
Generally the application code should be run inside test cases, and not from the test-discovery code that runs before the test harness even knows what the list of test cases is. That means it should be called from inside a `test` callback, not from `main` itself or from a `group` callback. There's a lot of application code that runs as part of calls like `store.addStreams` and `store.addUser`. So this `setupStore` method should be called from inside the test cases. Do that. In particular this is needed in order to make an async method out of PerAccountStore.handleEvent, which underlies those helpers like `addStreams`. Async calls especially need to be kept out of test-discovery time, because `package:test` requires all the test discovery to be completed synchronously.
1 parent 625389a commit e63ec7b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/model/internal_link_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ void main() {
3131

3232
void testExpectedNarrows(List<(String, Narrow?)> testCases, {
3333
List<ZulipStream>? streams,
34-
PerAccountStore? store,
3534
List<User>? users,
3635
}) {
37-
assert((streams != null || users != null) ^ (store != null));
38-
store ??= setupStore(realmUrl: realmUrl, streams: streams, users: users);
36+
assert(streams != null || users != null);
3937
for (final testCase in testCases) {
4038
final String urlString = testCase.$1;
41-
final Uri url = store.tryResolveUrl(urlString)!;
4239
final Narrow? expected = testCase.$2;
4340
test(urlString, () {
44-
check(parseInternalLink(url, store!)).equals(expected);
41+
final store = setupStore(realmUrl: realmUrl, streams: streams, users: users);
42+
final url = store.tryResolveUrl(urlString)!;
43+
check(parseInternalLink(url, store)).equals(expected);
4544
});
4645
}
4746
}

0 commit comments

Comments
 (0)