I have a config.ts which returns an object:
// Config is an interface that I use to know which values are expected
export default function getConfig(): Config {
return {amount: 50}
}
I have a class (../src/models/item.model) that has a dependency to the config.ts:
import getConfig from '../config/config';
class Item{
_id: number;
amount: number;
constructor(_id: number) {
this._id = _id;
this.amount = getConfig().amount;
}
}
export default Item
I would like to write some tests with a different amount value. The default value is 50 (set in config.ts), but in my item.test.ts I would like to use a value of 100. I'm trying to achieve this by using Proxyquire:
it('should use voxelsize of custom config', (done) => {
const itemModel = proxyquire('../src/models/item.model', {
'../config/config': function getConfig() {
return {amount: 100};
}
}).default;
const testItem = new itemModel(1)
expect(testItem.amount).to.equal(100);
done()
})
testItem.amount is in reality 50 (so it still uses the original configuration file). This should be 100.
How can I let the test pass?