mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 08:34:08 +02:00
Extract Component config functionality to a separate class (#33872)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
78
js/tests/unit/util/config.spec.js
Normal file
78
js/tests/unit/util/config.spec.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import Config from '../../../src/util/config'
|
||||
|
||||
class DummyConfigClass extends Config {
|
||||
static get NAME() {
|
||||
return 'dummy'
|
||||
}
|
||||
}
|
||||
|
||||
describe('Config', () => {
|
||||
const name = 'dummy'
|
||||
describe('NAME', () => {
|
||||
it('should return plugin NAME', () => {
|
||||
expect(DummyConfigClass.NAME).toEqual(name)
|
||||
})
|
||||
})
|
||||
|
||||
describe('DefaultType', () => {
|
||||
it('should return plugin default type', () => {
|
||||
expect(DummyConfigClass.DefaultType).toEqual(jasmine.any(Object))
|
||||
})
|
||||
})
|
||||
|
||||
describe('Default', () => {
|
||||
it('should return plugin defaults', () => {
|
||||
expect(DummyConfigClass.Default).toEqual(jasmine.any(Object))
|
||||
})
|
||||
})
|
||||
|
||||
describe('typeCheckConfig', () => {
|
||||
it('should check type of the config object', () => {
|
||||
spyOnProperty(DummyConfigClass, 'DefaultType', 'get').and.returnValue({
|
||||
toggle: 'boolean',
|
||||
parent: '(string|element)'
|
||||
})
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: 777
|
||||
}
|
||||
|
||||
const obj = new DummyConfigClass()
|
||||
expect(() => {
|
||||
obj._typeCheckConfig(config)
|
||||
}).toThrowError(TypeError, obj.constructor.NAME.toUpperCase() + ': Option "parent" provided type "number" but expected type "(string|element)".')
|
||||
})
|
||||
|
||||
it('should return null stringified when null is passed', () => {
|
||||
spyOnProperty(DummyConfigClass, 'DefaultType', 'get').and.returnValue({
|
||||
toggle: 'boolean',
|
||||
parent: '(null|element)'
|
||||
})
|
||||
|
||||
const obj = new DummyConfigClass()
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: null
|
||||
}
|
||||
|
||||
obj._typeCheckConfig(config)
|
||||
expect().nothing()
|
||||
})
|
||||
|
||||
it('should return undefined stringified when undefined is passed', () => {
|
||||
spyOnProperty(DummyConfigClass, 'DefaultType', 'get').and.returnValue({
|
||||
toggle: 'boolean',
|
||||
parent: '(undefined|element)'
|
||||
})
|
||||
|
||||
const obj = new DummyConfigClass()
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: undefined
|
||||
}
|
||||
|
||||
obj._typeCheckConfig(config)
|
||||
expect().nothing()
|
||||
})
|
||||
})
|
||||
})
|
@@ -223,53 +223,6 @@ describe('Util', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('typeCheckConfig', () => {
|
||||
const namePlugin = 'collapse'
|
||||
|
||||
it('should check type of the config object', () => {
|
||||
const defaultType = {
|
||||
toggle: 'boolean',
|
||||
parent: '(string|element)'
|
||||
}
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: 777
|
||||
}
|
||||
|
||||
expect(() => {
|
||||
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||
}).toThrowError(TypeError, 'COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".')
|
||||
})
|
||||
|
||||
it('should return null stringified when null is passed', () => {
|
||||
const defaultType = {
|
||||
toggle: 'boolean',
|
||||
parent: '(null|element)'
|
||||
}
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: null
|
||||
}
|
||||
|
||||
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||
expect().nothing()
|
||||
})
|
||||
|
||||
it('should return undefined stringified when undefined is passed', () => {
|
||||
const defaultType = {
|
||||
toggle: 'boolean',
|
||||
parent: '(undefined|element)'
|
||||
}
|
||||
const config = {
|
||||
toggle: true,
|
||||
parent: undefined
|
||||
}
|
||||
|
||||
Util.typeCheckConfig(namePlugin, config, defaultType)
|
||||
expect().nothing()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isVisible', () => {
|
||||
it('should return false if the element is not defined', () => {
|
||||
expect(Util.isVisible(null)).toBeFalse()
|
||||
|
Reference in New Issue
Block a user