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

163
Visualizações
Imported variable undefined access imported constant from callback function

Using jest-puppeteer to get the below 'page' object. That works fine.

My imported constant is coming back as undefined when in the evaluate function. I'm unsure why, given it works right outside the function in the parent scope just fine...

const CONSTANTS = require('../../../constants/Config')
const DICTIONARY = require('../../../constants/Dictionary')

describe('Check that reevaluate review section', () => {
    // Blah blah //
    var apiCall = CONSTANTS.NODE_ENDPOINT + "/api" + '/1234'  // outputs correctly

    test("reevaluate options include 'Sunset'", async () => {
    // Blah blah //
        console.log('DICTIONARY.SUNSET :>> ', DICTIONARY.SUNSET);  // outputs correctly
        const element_is_visible = await page.evaluate(() => {
            console.log('DICTIONARY.SUNSET :>> ', DICTIONARY.SUNSET);  // says "DICTIONARY is undefined"
    // Blah blah //
        });
        expect(element_is_visible).toBe(true)
    })

});

Dictionary.js

export const PENDING = "Pending"
export const PENDING_BY_QUEUE = "Pending"
export const SUNSET = "Sunset"
export const DUPLICATE_STATUS_OPTION = "Duplicate"
export const WITHDRAW_STATUS_OPTION = "Withdraw"
export const RETIRED_STATUS_OPTION = "Retired"

I suspect this problem might have something to do with the mixing of ES6 imports and nodejs imports... but I'm not sure why.

about 4 years ago · Juan Pablo Isaza
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