mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-25 01:04:14 -05:00
chore: add error for incorrect load function (#591)
This commit is contained in:
@@ -13,6 +13,16 @@ describe('load', () => {
|
||||
clearFromCache('pie');
|
||||
});
|
||||
|
||||
it('should throw when load is not a function', async () => {
|
||||
const loader = { then: {} }; // fake promise
|
||||
try {
|
||||
await load('pie', '1.0.0', halo, loader);
|
||||
expect(0).to.equal(1);
|
||||
} catch (e) {
|
||||
expect(e.message).to.equal(`load of visualization 'pie v1.0.0' is not a fuction, wrap load promise in function`);
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw when resolving to a falsy value', async () => {
|
||||
const loader = () => false;
|
||||
try {
|
||||
|
||||
@@ -12,6 +12,9 @@ export async function load(name, version, { config }, loader) {
|
||||
const key = `${name}__${version}`;
|
||||
if (!LOADED[key]) {
|
||||
const sKey = `${name}${(version && ` v${version}`) || ''}`;
|
||||
if (loader && typeof loader !== 'function') {
|
||||
throw new Error(`load of visualization '${sKey}' is not a fuction, wrap load promise in function`);
|
||||
}
|
||||
const p = (loader || config.load)({
|
||||
name,
|
||||
version,
|
||||
|
||||
Reference in New Issue
Block a user