Answer the question
In order to leave comments, you need to log in
How to test a private static method that throws an exception?
constructor(settings: ISettings) {
Model.validateSettings(settings);
this.settings = settings;
}
private static validateSettings(settings: ISettings): void {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
}
let settings: ISettings;
beforeEach(() => {
settings = {
min: 0,
max: 1500,
isTwoRunners: true,
isScaleVisible: true,
isVertical: false,
isTooltipsVisible: true,
valueFrom: 1000,
valueTo: 1490,
step: 10,
};
});
describe('function validateSettings: ', () => {
test('"settings.min >= settings.max" should throw Error', () => {
settings.min = 2000;
settings.max = 1500;
expect(Model['validateSettings'](settings)).toThrow("'max' must be greater than 'min'");
});
});
Answer the question
In order to leave comments, you need to log in
expect(() => Model['validateSettings'](settings)).toThrow("'max' must be greater than 'min'");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question