Test for specialOn()

This commit is contained in:
Daniel Lugo 2021-09-22 17:52:29 -04:00
parent 762b704a5b
commit 2acb7bc379

View file

@ -7,6 +7,7 @@
const Gun = require('./GunSmith') const Gun = require('./GunSmith')
const words = require('random-words') const words = require('random-words')
const fs = require('fs') const fs = require('fs')
const debounce = require('lodash/debounce')
const logger = require('../../config/log') const logger = require('../../config/log')
@ -271,6 +272,33 @@ describe('gun smith', () => {
release() release()
}) })
it('provides an special on() that restarts gun when a value has not been obtained in a determinate amount of time', async done => {
// Kinda crappy test, this should be easier to test in real usage.
expect.assertions(1)
await whenReady()
jest.setTimeout(40000)
const initialProcCounter = instance._getProcCounter()
const node = instance.get(words()).get(words())
const secondValue = words()
node.specialOn(
debounce(data => {
if (data === secondValue) {
expect(instance._getProcCounter()).toEqual(initialProcCounter + 1)
done()
release()
}
})
)
setTimeout(() => {
node.put(secondValue)
}, 32000)
})
// TODO: find out why this test fucks up the previous one if it runs before // TODO: find out why this test fucks up the previous one if it runs before
// that one // that one
it('maps over a primitive set', async done => { it('maps over a primitive set', async done => {