specialOnce() test foundations

This commit is contained in:
Daniel Lugo 2021-09-17 17:07:54 -04:00
parent 91e2ec08c5
commit 89c206ff03
2 changed files with 24 additions and 1 deletions

View file

@ -233,7 +233,6 @@ const isReady = () =>
isReady().then(res)
}, 1000)
} else {
logger.info('isReady')
res()
}
})

View file

@ -426,4 +426,28 @@ describe('gun smith', () => {
done()
release()
})
// eslint-disable-next-line jest/expect-expect
it('provides an special once() that restarts gun until a value is fetched', async done => {
expect.assertions(1)
await whenReady()
jest.setTimeout(100000)
const a = words()
const b = words()
const node = instance.get(a).get(b)
const value = words()
node.once(data => {
if (data === value) {
expect(data).toEqual(value)
jest.setTimeout(5000)
done()
}
})
setTimeout(() => {
node.put(value)
}, 9000)
})
})