Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalshit27 committed Feb 4, 2025
1 parent 517fec5 commit aefd05e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/configFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { expect } from 'chai';
import { configFactory, ConfigFunction } from '../src/configFactory';
import { Config } from '../src/types';

describe('configFactory', () => {
let config: ReturnType<typeof configFactory>;

beforeEach(() => {
config = configFactory();
});

it('should set and get configuration values', () => {
config.setValue('someKey' as keyof Config, 'someValue');
expect(config('someKey' as keyof Config)).to.equal('someValue');
});

it('should throw an error if no provider is set and key is not in settings', () => {
expect(() => config('someKey' as keyof Config)).to.throw(
'A configuration provider has not been set'
);
});

it('should use the provider function to get configuration values', () => {
const providerFunction: ConfigFunction = (key) => {
if ((key as string) === 'someKey') return 'providedValue';
return null;
};
config.setProvider(providerFunction);
expect(config('someKey' as keyof Config)).to.equal('providedValue');
});

it('should prioritize settings over provider function', () => {
config.setValue('someKey' as keyof Config, 'someValue');
const providerFunction: ConfigFunction = (key) => {
if ((key as string) === 'someKey') return 'providedValue';
return null;
};
config.setProvider(providerFunction);
expect(config('someKey' as keyof Config)).to.equal('someValue');
});
});

0 comments on commit aefd05e

Please sign in to comment.