From 2acb7bc3793a8653d3225005007ad284382b4d46 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 22 Sep 2021 17:52:29 -0400 Subject: [PATCH] Test for specialOn() --- utils/GunSmith/GunSmith.spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/utils/GunSmith/GunSmith.spec.js b/utils/GunSmith/GunSmith.spec.js index 47a7fb4d..f5265ba9 100644 --- a/utils/GunSmith/GunSmith.spec.js +++ b/utils/GunSmith/GunSmith.spec.js @@ -7,6 +7,7 @@ const Gun = require('./GunSmith') const words = require('random-words') const fs = require('fs') +const debounce = require('lodash/debounce') const logger = require('../../config/log') @@ -271,6 +272,33 @@ describe('gun smith', () => { 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 // that one it('maps over a primitive set', async done => {