Skip to content

Commit 0e7840a

Browse files
committed
fix(test): assert observable Dio mutations in configureDriver tests (#35)
Tests now verify interceptor count changes on the driver-owned Dio instance instead of only asserting callbacks were invoked. Ensures configurator receives the actual Dio instance, not a fresh one.
1 parent 3f3a253 commit 0e7840a

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

test/network/network_test.dart

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,49 @@ void main() {
105105
driver.addInterceptor(interceptor);
106106
});
107107

108-
test('configureDriver() applies configurator to Dio instance', () {
109-
var called = false;
108+
test('configureDriver() mutates the driver-owned Dio instance', () {
109+
late int countBefore;
110+
110111
driver.configureDriver((dio) {
111-
called = true;
112+
countBefore = dio.interceptors.length;
112113
dio.interceptors.add(
113114
InterceptorsWrapper(
114115
onRequest: (options, handler) => handler.next(options),
115116
),
116117
);
117118
});
118119

119-
expect(called, isTrue);
120+
// Verify interceptor persists on the same Dio instance.
121+
late int countAfter;
122+
driver.configureDriver((dio) {
123+
countAfter = dio.interceptors.length;
124+
});
125+
126+
expect(countAfter, countBefore + 1);
120127
});
121128

122129
test('configureDriver() allows multiple configurators', () {
123-
var firstCalled = false;
124-
var secondCalled = false;
130+
late int countAfterFirst;
131+
late int countAfterSecond;
125132

126133
driver.configureDriver((dio) {
127-
firstCalled = true;
134+
dio.interceptors.add(
135+
InterceptorsWrapper(
136+
onRequest: (options, handler) => handler.next(options),
137+
),
138+
);
139+
countAfterFirst = dio.interceptors.length;
128140
});
129141
driver.configureDriver((dio) {
130-
secondCalled = true;
142+
dio.interceptors.add(
143+
InterceptorsWrapper(
144+
onRequest: (options, handler) => handler.next(options),
145+
),
146+
);
147+
countAfterSecond = dio.interceptors.length;
131148
});
132149

133-
expect(firstCalled, isTrue);
134-
expect(secondCalled, isTrue);
150+
expect(countAfterSecond, countAfterFirst + 1);
135151
});
136152
});
137153
}

0 commit comments

Comments
 (0)