fix: use placeholder dht/pubsub (#1193)

Instead of making the `.dht` and `.pubsub` properties optional, use dummy implementations that throw exceptions if they are not configured.

This way we don't have to null guard everywhere they are accessed.
This commit is contained in:
Alex Potsides
2022-04-21 15:46:06 +01:00
committed by GitHub
parent 147304449e
commit 5397137c65
14 changed files with 186 additions and 78 deletions

View File

@ -13,15 +13,17 @@ describe('DHT subsystem is configurable', () => {
}
})
it('should not exist if no module is provided', async () => {
it('should throw if no module is provided', async () => {
libp2p = await createLibp2p(createSubsystemOptions({
dht: undefined
}))
expect(libp2p.dht).to.not.exist()
await libp2p.start()
await expect(libp2p.dht.getMode()).to.eventually.be.rejected()
})
it('should exist if the module is provided', async () => {
it('should not throw if the module is provided', async () => {
libp2p = await createLibp2p(createSubsystemOptions())
expect(libp2p.dht).to.exist()
await libp2p.start()
await expect(libp2p.dht.getMode()).to.eventually.equal('client')
})
})