Web.Components: utils: emailSettings: added tests for checking throw errors

This commit is contained in:
Daniil Senkiv 2019-10-16 17:35:43 +03:00
parent 3e8b7be6c4
commit f86d300e78
2 changed files with 78 additions and 7 deletions

View File

@ -18,7 +18,7 @@ export class EmailSettings {
this._allowDomainPunycode = value;
}
else {
throw `Invalid value ${value} for allowDomainPunycode option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowDomainPunycode option. Use boolean value`);
}
}
@ -31,7 +31,7 @@ export class EmailSettings {
this._allowLocalPartPunycode = value;
}
else {
throw `Invalid value ${value} for allowLocalPartPunycode option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowLocalPartPunycode option. Use boolean value`);
}
}
@ -44,7 +44,7 @@ export class EmailSettings {
this._allowDomainIp = value;
}
else {
throw `Invalid value ${value} for allowDomainIp option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowDomainIp option. Use boolean value`);
}
}
@ -57,7 +57,7 @@ export class EmailSettings {
this._allowStrictLocalPart = value;
}
else {
throw `Invalid value ${value} for allowStrictLocalPart option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowStrictLocalPart option. Use boolean value`);
}
}
@ -70,7 +70,7 @@ export class EmailSettings {
this._allowSpaces = value;
}
else {
throw `Invalid value ${value} for allowSpaces option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowSpaces option. Use boolean value`);
}
}
@ -83,7 +83,7 @@ export class EmailSettings {
this._allowName = value;
}
else {
throw `Invalid value ${value} for allowName option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowName option. Use boolean value`);
}
}
@ -96,7 +96,7 @@ export class EmailSettings {
this._allowLocalDomainName = value;
}
else {
throw `Invalid value ${value} for allowLocalDomainName option. Use boolean value`
throw new TypeError (`Invalid value ${value} for allowLocalDomainName option. Use boolean value`);
}
}

View File

@ -62,6 +62,77 @@ describe('emailSettings', () => {
expect(newSettings).toStrictEqual(disabledSettings);
});
it('set invalid (non-boolean) value for allowLocalDomainName setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowLocalDomainName = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowDomainPunycode setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowDomainPunycode = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowLocalPartPunycode setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowLocalPartPunycode = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowDomainIp setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowDomainIp = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowStrictLocalPart setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowStrictLocalPart = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowSpaces setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowSpaces = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
it('set invalid (non-boolean) value for allowName setting', () => {
const emailSettings = new EmailSettings();
try {
emailSettings.allowName = '1';
} catch (err) {
expect(err.name).toBe('TypeError');
}
});
// test isEqualEmailSettings function
it('is not equal email settings', () => {