Skip to content

Commit 3885a15

Browse files
committed
test(cli): restore fetch with spyOn so the stub cannot outlive its test
vi.stubGlobal is not undone by restoreAllMocks, so the completed-auth response would have leaked into whatever ran next. The rest of this file already spies on globalThis.fetch, which the existing teardown restores.
1 parent 2686327 commit 3885a15

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/sim-cli/src/auth/device-flow.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,18 @@ describe('createAuthRequest', () => {
151151
/^https:\/\/host\.test\/sim\/cli\/auth\?/
152152
)
153153

154-
const fetchMock = vi.fn().mockResolvedValue(
154+
// `spyOn`, like the rest of this file: `restoreAllMocks` in teardown undoes
155+
// it, whereas a `stubGlobal` would outlive the test and leak this
156+
// completed-auth response into whatever ran next.
157+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
155158
new Response(JSON.stringify({ status: 'complete', key: { id: 'k', apiKey: 'sk' } }), {
156159
status: 200,
157160
headers: { 'content-type': 'application/json' },
158161
})
159162
)
160-
vi.stubGlobal('fetch', fetchMock)
161163

162164
await pollForKey(prefixed, auth)
163-
expect(fetchMock.mock.calls[0][0]).toBe('https://host.test/sim/api/cli/auth/poll')
165+
expect(fetchSpy.mock.calls[0][0]).toBe('https://host.test/sim/api/cli/auth/poll')
164166
})
165167

166168
it('omits an absent workspace rather than sending it blank', () => {

0 commit comments

Comments
 (0)