Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
Variable 'email' should not be initialized on declaration

I'm trying to create a random generator for emails in my cypress code

this is my exemple :

export function userEmail(): string {
  let email = "",
    domainName = "",
    possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  for (let i = 0; i < tabSize9; i++)
    email += possible.charAt(Math.floor(Math.random() * possible.length));

  domainName += possible.charAt(Math.floor(Math.random() * possible.length));

  return `${email}@${domainName}.com`;
}

it's working for me as well , but the problem is when i lunch my eslint script , it says to me that the variable email should not be initialized on declaration , even my domainName variable

Any help !

thank you in advance

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Just split the declarations on 3 different lines

let email = "";
let domainName = "";
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
about 4 years ago · Juan Pablo Isaza Relatório

0

You try this :

export function userEmail(): string {
 const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 let email = "";
 let domainName = "";
  for (let i = 0; i < tabSize9; i++){
    email += possible.charAt(Math.floor(Math.random() * possible.length));
    domainName += possible.charAt(Math.floor(Math.random() * possible.length));
  }
  return `${email}@${domainName}.com`;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can also use faker.js to generate random emails.

  1. Install faker js with npm install @faker-js/faker --save-dev

  2. In order to have faker working properly, you need to check if these compilerOptions are set correctly in your tsconfig file:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "moduleResolution": "Node"
  }
}
  1. In your test
import { faker } from '@faker-js/faker';

export function userEmail(): string {
  return faker.internet.email();
}

You can play around with what type of random emails you want to generate. Like if you want to keep the domain name or first, the last name constant etc. Refer Faker Js Document

faker.internet.email(firstName?: string, lastName?: string, provider?: string, options?: {
  allowSpecialCharacters: boolean
} = { allowSpecialCharacters: false }): string
faker.internet.email() // => "Larry_Ratke85@yahoo.com"
faker.internet.email() // 'Kassandra4@hotmail.com'
faker.internet.email('Jeanne', 'Doe') // 'Jeanne63@yahoo.com'
faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev') // 'Jeanne_Doe88@example.fakerjs.dev'
faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev', { allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev'
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda