Skip to content

Commit 8c63727

Browse files
committed
fixed unit tests
1 parent a84e27b commit 8c63727

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

packages/event-processor/__tests__/pendingEventsDispatcher.spec.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ describe('LocalStoragePendingEventsDispatcher', () => {
7272
expect((originalEventDispatcher.dispatchEvent as unknown) as jest.Mock).toBeCalledTimes(1)
7373
expect(internalDispatchCall[0]).toEqual(eventV1Request)
7474

75-
// assert that the passed in callback to pendingEventsDispatcher was called
76-
expect(callback).toHaveBeenCalledTimes(1)
77-
expect(callback).toHaveBeenCalledWith({ statusCode: 200 })
78-
done()
75+
setTimeout(() => {
76+
// assert that the passed in callback to pendingEventsDispatcher was called
77+
expect(callback).toHaveBeenCalledTimes(1)
78+
expect(callback).toHaveBeenCalledWith({ statusCode: 200 })
79+
done()
80+
})
7981
})
8082
})
8183

@@ -100,10 +102,12 @@ describe('LocalStoragePendingEventsDispatcher', () => {
100102
expect((originalEventDispatcher.dispatchEvent as unknown) as jest.Mock).toBeCalledTimes(1)
101103
expect(internalDispatchCall[0]).toEqual(eventV1Request)
102104

103-
// assert that the passed in callback to pendingEventsDispatcher was called
104-
expect(callback).toHaveBeenCalledTimes(1)
105-
expect(callback).toHaveBeenCalledWith({ statusCode: 400})
106-
done()
105+
setTimeout(() => {
106+
// assert that the passed in callback to pendingEventsDispatcher was called
107+
expect(callback).toHaveBeenCalledTimes(1)
108+
expect(callback).toHaveBeenCalledWith({ statusCode: 400})
109+
done()
110+
})
107111
})
108112
})
109113
})
@@ -135,7 +139,7 @@ describe('PendingEventsDispatcher', () => {
135139

136140
describe('dispatch', () => {
137141
describe('when the dispatch is successful', () => {
138-
it('should save the pendingEvent to the store and remove it once dispatch is completed', async () => {
142+
it('should save the pendingEvent to the store and remove it once dispatch is completed', async (done) => {
139143
const callback = jest.fn()
140144
const eventV1Request: EventV1Request = {
141145
url: 'http://cdn.com',
@@ -164,16 +168,19 @@ describe('PendingEventsDispatcher', () => {
164168
).toBeCalledTimes(1)
165169
expect(internalDispatchCall[0]).toEqual(eventV1Request)
166170

167-
// assert that the passed in callback to pendingEventsDispatcher was called
168-
expect(callback).toHaveBeenCalledTimes(1)
169-
expect(callback).toHaveBeenCalledWith({ statusCode: 200 })
171+
setTimeout(async () => {
172+
// assert that the passed in callback to pendingEventsDispatcher was called
173+
expect(callback).toHaveBeenCalledTimes(1)
174+
expect(callback).toHaveBeenCalledWith({ statusCode: 200 })
170175

171-
expect(await store.values()).toHaveLength(0)
176+
expect(await store.values()).toHaveLength(0)
177+
done()
178+
})
172179
})
173180
})
174181

175182
describe('when the dispatch is unsuccessful', () => {
176-
it('should save the pendingEvent to the store and remove it once dispatch is completed', async () => {
183+
it('should save the pendingEvent to the store and remove it once dispatch is completed', async (done) => {
177184
const callback = jest.fn()
178185
const eventV1Request: EventV1Request = {
179186
url: 'http://cdn.com',
@@ -202,11 +209,14 @@ describe('PendingEventsDispatcher', () => {
202209
).toBeCalledTimes(1)
203210
expect(internalDispatchCall[0]).toEqual(eventV1Request)
204211

205-
// assert that the passed in callback to pendingEventsDispatcher was called
206-
expect(callback).toHaveBeenCalledTimes(1)
207-
expect(callback).toHaveBeenCalledWith({ statusCode: 400 })
212+
setTimeout(async () => {
213+
// assert that the passed in callback to pendingEventsDispatcher was called
214+
expect(callback).toHaveBeenCalledTimes(1)
215+
expect(callback).toHaveBeenCalledWith({ statusCode: 400 })
208216

209-
expect(await store.values()).toHaveLength(0)
217+
expect(await store.values()).toHaveLength(0)
218+
done()
219+
})
210220
})
211221
})
212222
})

0 commit comments

Comments
 (0)