js-libp2p-secio/test/support.spec.js
Friedel Ziegelmayer 9d3437e8d8 More implementation
2016-05-22 01:03:53 +02:00

55 lines
1.1 KiB
JavaScript

/* eslint-env mocha */
'use strict'
const expect = require('chai').expect
const support = require('../src/support')
describe('support', () => {
describe('theBest', () => {
it('returns the first matching element, preferring p1', () => {
const order = 1
const p1 = ['hello', 'world']
const p2 = ['world', 'hello']
expect(
support.theBest(order, p1, p2)
).to.be.eql(
'hello'
)
})
it('returns the first matching element, preferring p2', () => {
const order = -1
const p1 = ['hello', 'world']
const p2 = ['world', 'hello']
expect(
support.theBest(order, p1, p2)
).to.be.eql(
'world'
)
})
it('returns the first element if the same', () => {
const order = 0
const p1 = ['hello', 'world']
const p2 = p1
expect(
support.theBest(order, p1, p2)
).to.be.eql(
'hello'
)
})
it('throws if no matching element was found', () => {
expect(
() => support.theBest(1, ['hello'], ['world'])
).to.throw(
/No algorithms in common/
)
})
})
})