Files
shields/core/base-service/loader.spec.js
Paul Melnikow a0da978886 Bury the loader fixtures with the code that uses them (#3407)
One less thing to have in the root of the project!
2019-05-02 12:36:00 -04:00

60 lines
2.0 KiB
JavaScript

'use strict'
const { expect } = require('chai')
const { loadServiceClasses, InvalidService } = require('./loader')
describe('loadServiceClasses function', function() {
it('throws if module exports empty', function() {
expect(() =>
loadServiceClasses(['./loader-test-fixtures/empty-undefined.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['./loader-test-fixtures/empty-array.fixture.js'])
).to.throw()
expect(() =>
loadServiceClasses(['./loader-test-fixtures/empty-object.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['./loader-test-fixtures/empty-no-export.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses([
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
'./loader-test-fixtures/empty-array.fixture.js',
])
).to.throw(InvalidService)
})
it('throws if module exports invalid', function() {
expect(() =>
loadServiceClasses(['./loader-test-fixtures/invalid-no-base.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses([
'./loader-test-fixtures/invalid-wrong-base.fixture.js',
])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['./loader-test-fixtures/invalid-mixed.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses([
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
'./loader-test-fixtures/invalid-no-base.fixture.js',
])
).to.throw(InvalidService)
})
it('registers services if module exports valid service classes', function() {
expect(
loadServiceClasses([
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-object.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
])
).to.have.length(5)
})
})