mirror of
https://github.com/apache/superset.git
synced 2026-04-10 11:55:24 +00:00
* add unit tests * add test structure * add unit tests for Registry * add LoaderRegistry unit test * add unit test for makeSingleton * add type check * add plugin data structures * simplify API * add preset tests * update test message * fix lint * update makeSingleton * update Plugin, Preset and unit test * revise Registry code * update unit test, add remove function * update test * update unit test * update plugin unit test * add .keys(), .entries() and .entriesAsPromise() * update test description
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import { describe, it } from 'mocha';
|
|
import { expect } from 'chai';
|
|
import makeSingleton from '../../../src/utils/makeSingleton';
|
|
|
|
describe('makeSingleton()', () => {
|
|
class Dog {
|
|
constructor(name) {
|
|
this.name = name;
|
|
}
|
|
sit() {
|
|
this.isSitting = true;
|
|
}
|
|
}
|
|
describe('makeSingleton(BaseClass)', () => {
|
|
const getInstance = makeSingleton(Dog);
|
|
|
|
it('returns a function for getting singleton instance of a given base class', () => {
|
|
expect(getInstance).to.be.a('Function');
|
|
expect(getInstance()).to.be.instanceOf(Dog);
|
|
});
|
|
it('returned function returns same instance across all calls', () => {
|
|
expect(getInstance()).to.equal(getInstance());
|
|
});
|
|
});
|
|
describe('makeSingleton(BaseClass, ...args)', () => {
|
|
const getInstance = makeSingleton(Dog, 'Doug');
|
|
|
|
it('returns a function for getting singleton instance of a given base class constructed with the given arguments', () => {
|
|
expect(getInstance).to.be.a('Function');
|
|
expect(getInstance()).to.be.instanceOf(Dog);
|
|
expect(getInstance().name).to.equal('Doug');
|
|
});
|
|
it('returned function returns same instance across all calls', () => {
|
|
expect(getInstance()).to.equal(getInstance());
|
|
});
|
|
});
|
|
|
|
});
|