Skip to content

Commit

Permalink
chore: add test to assert peer ids can be passed to stubs (#2814)
Browse files Browse the repository at this point in the history
Makes sure we can use peer ids with sinon stubs without custom matchers.
  • Loading branch information
achingbrain authored Nov 8, 2024
1 parent 32ca76f commit 18e8e1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/peer-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"uint8arrays": "^5.1.0"
},
"devDependencies": {
"aegir": "^44.0.1"
"aegir": "^44.0.1",
"sinon": "^19.0.2"
},
"sideEffects": false
}
8 changes: 8 additions & 0 deletions packages/peer-id/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'aegir/chai'
import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { identity } from 'multiformats/hashes/identity'
import Sinon from 'sinon'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { peerIdFromCID, peerIdFromMultihash, peerIdFromPrivateKey, peerIdFromString } from '../src/index.js'
import type { KeyType, PeerId } from '@libp2p/interface'
Expand Down Expand Up @@ -99,6 +100,13 @@ describe('PeerId', () => {

expect(peerId1).to.deep.equal(peerId2)
})

it('should be matched by sinon', () => {
const stub = Sinon.stub()
stub(peerId)

expect(stub.calledWith(peerId)).to.be.true()
})
})
})

Expand Down

0 comments on commit 18e8e1c

Please sign in to comment.