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

115
Visualizações
Error - This condition will always return 'false' since the types '"$value"' and '""' have no overlap

I have a code as following:

describe("Dynamic testing fields validations", () => {
        it.each`
          field         | value             | expectedMessage
          ${"username"} | ${""}             | ${"username is not allowed to be empty"}
          ${"username"} | ${"b".repeat(4)}  | ${"username length must be at least 5 characters long"}
          ${"username"} | ${"b".repeat(21)} | ${"username length must be less than or equal to 20 characters long"}
          ${"email"}    | ${""}             | ${"email is not allowed to be empty"}
          ${"email"}    | ${"mailcom"}      | ${"email must be a valid email"}
          ${"password"} | ${""}             | ${"password is not allowed to be empty"}
        `(
          `return $expectedMessage when $field is ${"$value"} === "" ? "${"empty"}" : "$value" characters long`,
          async ({ field, expectedMessage, value }) => {
            user.username = value;
            user.password = value;
            user.email = value;

            const res = await exec();

            const {
              validationErrors: { details },
            } = res.body;

            const result = Object.assign({}, ...details);

            expect(result[field]).toBe(expectedMessage);
          }
        );
      });

I'm receiving the following error :

This condition will always return 'false' since the types '"$value"' and '""' have no overlap when I do the conditional check in the ternary operator.

I have tried everything but without success. Can a good soul give me an indication of how to fix this and why I'm receiving this error ?

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

0

I think your problem is from this

${"$value"} === "" ? "${"empty"}" : "$value"

From your logic I can understand like this

  • If your value is empty, you return ${"empty"} (which is similar to your "$value")

  • If your value is not empty, you also return "$value"

You can simplify that logic this way

`return $expectedMessage when $field is "$value" characters long`
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