77 * into the (test-only) onopen replay path.
88 */
99
10+ import flushPromises from "flush-promises" ;
1011import { http , HttpResponse } from "msw" ;
1112import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
1213
@@ -51,7 +52,7 @@ describe("useNotificationSSE viewer subscriptions", () => {
5152
5253 it ( "POSTs once per first subscriber for a given history id" , async ( ) => {
5354 addHistoryViewerSubscription ( "hist-A" ) ;
54- await Promise . resolve ( ) ;
55+ await flushPromises ( ) ;
5556 expect ( requests ) . toHaveLength ( 1 ) ;
5657 expect ( requests [ 0 ] ?. method ) . toBe ( "POST" ) ;
5758 expect ( requests [ 0 ] ?. history_ids ) . toEqual ( [ "hist-A" ] ) ;
@@ -60,39 +61,39 @@ describe("useNotificationSSE viewer subscriptions", () => {
6061 it ( "refcounts duplicate subscriptions — second add is a no-op on the wire" , async ( ) => {
6162 addHistoryViewerSubscription ( "hist-A" ) ;
6263 addHistoryViewerSubscription ( "hist-A" ) ;
63- await Promise . resolve ( ) ;
64+ await flushPromises ( ) ;
6465 expect ( requests . filter ( ( r ) => r . method === "POST" ) ) . toHaveLength ( 1 ) ;
6566 } ) ;
6667
6768 it ( "only DELETEs when the last subscriber for an id releases" , async ( ) => {
6869 addHistoryViewerSubscription ( "hist-A" ) ;
6970 addHistoryViewerSubscription ( "hist-A" ) ;
70- await Promise . resolve ( ) ;
71+ await flushPromises ( ) ;
7172 const postCount = requests . filter ( ( r ) => r . method === "POST" ) . length ;
7273
7374 removeHistoryViewerSubscription ( "hist-A" ) ;
74- await Promise . resolve ( ) ;
75+ await flushPromises ( ) ;
7576 // First remove still has one outstanding refcount — must not DELETE yet.
7677 expect ( requests . filter ( ( r ) => r . method === "DELETE" ) ) . toHaveLength ( 0 ) ;
7778 expect ( requests . filter ( ( r ) => r . method === "POST" ) ) . toHaveLength ( postCount ) ;
7879
7980 removeHistoryViewerSubscription ( "hist-A" ) ;
80- await Promise . resolve ( ) ;
81+ await flushPromises ( ) ;
8182 const deletes = requests . filter ( ( r ) => r . method === "DELETE" ) ;
8283 expect ( deletes ) . toHaveLength ( 1 ) ;
8384 expect ( deletes [ 0 ] ?. history_ids ) . toEqual ( [ "hist-A" ] ) ;
8485 } ) ;
8586
8687 it ( "ignores unsubscribes for ids that were never subscribed" , async ( ) => {
8788 removeHistoryViewerSubscription ( "hist-never" ) ;
88- await Promise . resolve ( ) ;
89+ await flushPromises ( ) ;
8990 expect ( requests ) . toHaveLength ( 0 ) ;
9091 } ) ;
9192
9293 it ( "tracks distinct history ids independently" , async ( ) => {
9394 addHistoryViewerSubscription ( "hist-A" ) ;
9495 addHistoryViewerSubscription ( "hist-B" ) ;
95- await Promise . resolve ( ) ;
96+ await flushPromises ( ) ;
9697 const ids = requests . filter ( ( r ) => r . method === "POST" ) . map ( ( r ) => r . history_ids [ 0 ] ) ;
9798 expect ( new Set ( ids ) ) . toEqual ( new Set ( [ "hist-A" , "hist-B" ] ) ) ;
9899 } ) ;
0 commit comments