singletons
Version:
Helps create and manage families of singletons based on customizable conditions
34 lines (29 loc) • 827 B
JavaScript
import {expect} from 'chai';
import {SingletonFactory} from '../../src/singletons';
import sig from 'sig';
describe(`Testing README.md examples`, function () {
it('Function looseKey(...args) example', function () {
class Class {
constructor (str) {
this.str = str;
}
};
const Singleton = SingletonFactory(
Class,
['literal'],
{
customArgs: [
[String, {
convert (arg) {
return arg.match(/!$/) ? arg : arg + '!';
},
}],
],
}
);
expect(Singleton.key('hello')).to.equal(sig('hello'));
expect(Singleton.key('hello!')).to.equal(sig('hello!'));
expect(Singleton.looseKey('hello')).to.equal(sig('hello!'));
expect(Singleton.looseKey('hello!')).to.equal(sig('hello!'));
});
});