@eluvio/elv-js-helpers
Version:
A collection of Javascript helper functions used by several Eluvio libraries.
24 lines (20 loc) • 1.01 kB
JavaScript
const TH = require('../../../test-helpers')
const assertNeighborsPass = TH.requireSrcFile('ModelAssertion/assertNeighborsPass')
describe('assertNeighborsPass', () => {
it('should work as expected', () => {
const defBasicModel = TH.requireSrcFile('ModelFactory/defBasicModel')
const kind = TH.requireSrcFile('Validation/kind')
// Note use of spread operator (...) to unpack the array returned by assertNeighborsPass()
const ArrayAllSameKindModel = defBasicModel('ArrayAllSameKindModel', Array).extend()
.assert(
...assertNeighborsPass(
(x, y) => kind(x) === kind(y),
'elements are not all of the same kind'
)
)
ArrayAllSameKindModel([1, 2, 3]).should.eql([1, 2, 3])
ArrayAllSameKindModel([]).should.eql([])
TH.expect(() => ArrayAllSameKindModel([42, 'a'])).to.throw('Value elements are not all of the same kind (got: [42,"a"])')
TH.expect(() => ArrayAllSameKindModel('foo')).to.throw('expecting Array, got String "foo"')
})
})