Skip to content

Commit 18e8e1c

Browse files
authored
chore: add test to assert peer ids can be passed to stubs (#2814)
Makes sure we can use peer ids with sinon stubs without custom matchers.
1 parent 32ca76f commit 18e8e1c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/peer-id/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"uint8arrays": "^5.1.0"
6161
},
6262
"devDependencies": {
63-
"aegir": "^44.0.1"
63+
"aegir": "^44.0.1",
64+
"sinon": "^19.0.2"
6465
},
6566
"sideEffects": false
6667
}

packages/peer-id/test/index.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { expect } from 'aegir/chai'
44
import { base58btc } from 'multiformats/bases/base58'
55
import { CID } from 'multiformats/cid'
66
import { identity } from 'multiformats/hashes/identity'
7+
import Sinon from 'sinon'
78
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
89
import { peerIdFromCID, peerIdFromMultihash, peerIdFromPrivateKey, peerIdFromString } from '../src/index.js'
910
import type { KeyType, PeerId } from '@libp2p/interface'
@@ -99,6 +100,13 @@ describe('PeerId', () => {
99100

100101
expect(peerId1).to.deep.equal(peerId2)
101102
})
103+
104+
it('should be matched by sinon', () => {
105+
const stub = Sinon.stub()
106+
stub(peerId)
107+
108+
expect(stub.calledWith(peerId)).to.be.true()
109+
})
102110
})
103111
})
104112

0 commit comments

Comments
 (0)