Skip to content
Permalink
Browse files

fix: fix test on develop

A test was relying on a time based delay to wait for some notifications to fire.
Added a callback wrapper to the original callback so that it counts the amount of
notifications and resolves a promise.
  • Loading branch information...
eburgos authored and satello committed Mar 3, 2018
1 parent 1c3c6c3 commit 8f361c8a116d0e21bf741cd3d1970e115ce12672
Showing with 29 additions and 3 deletions.
  1. +29 −3 tests/kleros.test.js
@@ -14,6 +14,7 @@ describe('Kleros', () => {
let KlerosInstance
let storeProvider
let notificationCallback
let waitNotifications
let notifications = []

beforeAll(async () => {
@@ -37,6 +38,29 @@ describe('Kleros', () => {
notificationCallback = notification => {
notifications.push(notification)
}
waitNotifications = (initialAmount = undefined) => {
let amount
let currentAmount = 0
let notificationList = []
let resolver
let promise = new Promise(resolve => {
resolver = resolve
})
let callback = notification => {
notificationCallback(notification)
notificationList.push(notification)
currentAmount += 1
if (typeof amount !== 'undefined' && currentAmount >= amount)
resolver(notificationList)
}
let setAmount = n => {
amount = n
if (currentAmount >= amount) resolver(notificationList)
}
if (typeof initialAmount !== 'undefined') setAmount(initialAmount)

return { promise, callback, setAmount }
}
})

beforeEach(async () => {
@@ -835,14 +859,16 @@ describe('Kleros', () => {

// spin up juror1 notifications listener. should populate missed notifications
notifications = []
let { promise: waitPromise, callback: waitCallback } = waitNotifications(
2
)
await KlerosInstance.watchForEvents(
klerosCourt.address,
juror1,
notificationCallback
waitCallback
)

// FIXME unreliable. need a better way to "wait" on getting caught up on events
await delaySecond(10)
await waitPromise

const juror1Profile = await storeProvider.getUserProfile(juror1)
expect(juror1Profile.disputes.length).toEqual(1)

0 comments on commit 8f361c8

Please sign in to comment.
You can’t perform that action at this time.