diff --git a/frontend/src/utils/index.test.ts b/frontend/src/utils/index.test.ts index 766fcd120c90747de174fd7f61f9779ced7a5e5c..b1bfa9734572b46cfe2798efc2cdcc5793daad89 100644 --- a/frontend/src/utils/index.test.ts +++ b/frontend/src/utils/index.test.ts @@ -1,4 +1,4 @@ -import { isValidMobilePhoneNumber } from './index' +import { isValidEmail, isValidMobilePhoneNumber } from './index' // Mock i18next module to return a translation that just returns the key jest.mock('i18next', () => ({ @@ -12,3 +12,16 @@ test('Invalid phone number', async () => { test('Valid phone number', async () => { expect(isValidMobilePhoneNumber('+47 97510000')).toEqual(true) }) + +test('Valid e-mail', async () => { + expect(isValidEmail('test@example.org')).toEqual(true) + expect(isValidEmail('Test.Tester@example.org')).toEqual(true) +}) + +test('Invalid e-mail', async () => { + expect(isValidEmail('testexample.org')).not.toEqual(true) + expect(isValidEmail('test')).not.toEqual(true) + // Treat special characters as invalid, some services allow them though + expect(isValidEmail('Øyvind.Åsen@example.org')).not.toEqual(true) + expect(isValidEmail('Test.Tester@åsen.org')).not.toEqual(true) +})