mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-31 06:41:08 +00:00
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.
30 lines
805 B
TypeScript
30 lines
805 B
TypeScript
/* eslint-env mocha */
|
|
|
|
import { expect } from 'aegir/chai'
|
|
import { createLibp2p, Libp2p } from '../../../src/index.js'
|
|
import { createSubsystemOptions } from './utils.js'
|
|
|
|
describe('DHT subsystem is configurable', () => {
|
|
let libp2p: Libp2p
|
|
|
|
afterEach(async () => {
|
|
if (libp2p != null) {
|
|
await libp2p.stop()
|
|
}
|
|
})
|
|
|
|
it('should throw if no module is provided', async () => {
|
|
libp2p = await createLibp2p(createSubsystemOptions({
|
|
dht: undefined
|
|
}))
|
|
await libp2p.start()
|
|
await expect(libp2p.dht.getMode()).to.eventually.be.rejected()
|
|
})
|
|
|
|
it('should not throw if the module is provided', async () => {
|
|
libp2p = await createLibp2p(createSubsystemOptions())
|
|
await libp2p.start()
|
|
await expect(libp2p.dht.getMode()).to.eventually.equal('client')
|
|
})
|
|
})
|