Skip to content

Commit 034d17f

Browse files
fix: correct test assertions and mock setup
- Fix settings test: add supportAccess and activityLogging to validKeys - Fix settings test: assertions now match what's being changed - Fix WebBluetoothTransport test: set device before changing connection state - Fix WebBluetoothTransport test: handle logs$ ReplaySubject buffered logs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5a6aa45 commit 034d17f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/__tests__/WebBluetoothTransport.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ describe("WebBluetoothTransport", () => {
9090
});
9191

9292
it("should handle connection state changes", (done) => {
93+
// Set device before changing connection state to avoid unhandled error
94+
// when _onDisconnected() tries to attach listener to device
95+
transport.device = mockDevice;
96+
9397
const states: BLUETOOTH_CONNECTION[] = [];
9498
transport.connection().subscribe((state) => {
9599
states.push(state);
@@ -203,6 +207,9 @@ describe("WebBluetoothTransport", () => {
203207
});
204208

205209
it("should check connection status", () => {
210+
// Set device before changing connection state to avoid unhandled error
211+
transport.device = mockDevice;
212+
206213
transport.connection$.next(BLUETOOTH_CONNECTION.CONNECTED);
207214
expect(transport.isConnected()).toBe(true);
208215

@@ -212,12 +219,17 @@ describe("WebBluetoothTransport", () => {
212219

213220
it("should add logs", (done) => {
214221
const testLog = "Test log message";
222+
transport.addLog(testLog);
223+
224+
// logs$ is a ReplaySubject, so we need to check if our log was added
225+
const logs: string[] = [];
215226
transport.logs$.subscribe((log) => {
216-
expect(log).toBe(testLog);
217-
done();
227+
logs.push(log);
228+
if (log === testLog) {
229+
expect(logs).toContain(testLog);
230+
done();
231+
}
218232
});
219-
220-
transport.addLog(testLog);
221233
});
222234

223235
it("should handle connection errors", async () => {

src/__tests__/settings.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jest.mock("../api/index", () => {
2626
}),
2727
changeSettings: jest.fn(async (settings) => {
2828
// Validate settings
29-
const validKeys = ["lsl", "bluetooth", "timesync", "deviceNickname"];
29+
const validKeys = ["lsl", "bluetooth", "timesync", "deviceNickname", "supportAccess", "activityLogging"];
3030
const hasInvalidKey = Object.keys(settings).some(
3131
(key) => !validKeys.includes(key)
3232
);
@@ -81,8 +81,8 @@ describe("Settings", () => {
8181
it("should update settings", (done) => {
8282
const newSettings = {
8383
lsl: true,
84-
bluetooth: true,
85-
timesync: true
84+
supportAccess: true,
85+
activityLogging: true
8686
};
8787

8888
neurosity

0 commit comments

Comments
 (0)