No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Inicializando nuestro framework

13/24
Recursos

Aportes 8

Preguntas 2

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

babel.config.js

module.exports = {
    presets: [
        [
            "@babel/preset-env",
            {
                targets: {
                    node: "current",
                },
            },
        ],
    ],
};

En windows obtuve este error!

PS C:\Users\walde\OneDrive\Escritorio\Personal\Cursos\Platzi\QA\Automatización\Framework> node_modules/.bin/jest --init     
node_modules/.bin/jest : No se puede cargar el archivo 
C:\Users\walde\OneDrive\Escritorio\Personal\Cursos\Platzi\QA\Automatización\Framework\node_modules\.bin\jest.ps1 porque la ejecución de scripts 
está deshabilitada en este sistema. Para obtener más información, consulta el tema about_Execution_Policies en 
https:/go.microsoft.com/fwlink/?LinkID=135170.
En línea: 1 Carácter: 1
+ node_modules/.bin/jest --init
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

para solventarlo seguí los siguientes pasos:

1-Ejecutar como administrador visual studio code
2- ejecutar el siguiente comando

Set-ExecutionPolicy -scope LocalMachine unrestricted

3-Ejecutar el comando

node_modules/.bin/jest --init 

En mi caso en Windows, no funcionó el comando:
node node_modules/.bin/jest --init
Funcionó asi:
node_modules/.bin/jest --init

si descomento las mismas lineas que en video en el archivo jest.config.js me da este error al ejecutar la prueba

 FAIL  __tests__/example.test.js
  ● Test suite failed to run
                                                                                                                                
    TypeError: Cannot read properties of undefined (reading 'bind')

      at Runtime._createJestObjectFor (node_modules/jest-runtime/build/index.js:2099:64) 

y si en el archiv example.test.js no lo coloco como se muestra a continuación también me da error

 const puppeteer = require('puppeteer');

describe('Google ',()=>{
    it('abrir el navegador', async()=>{
        const browser = await puppeteer.launch({
			headless: false,
			defaultViewport : null
		});
		const page = await browser.newPage();
        await page.goto('https://www.google.com/')
        await page.waitForTimeout(5000)
    },15000)
})

Con npx jest --init da el mismo resultado.

Esta es la forma uno y no funciona

describe('Google ',()=>{
   it('abrir el navegador', async()=>{
      await page.goto('https://www.google.com/')
      await page.waitForTimeout(5000)
   },15000)
})

Esta es la forma dos y si funciona

const puppeteer = require('puppeteer');

describe('Google ',()=>{
   it('abrir el navegador', async()=>{
      const browser = await puppeteer.launch({
      headless: false,
      defaultViewport : null
   });
   const page = await browser.newPage();
      await page.goto('https://www.google.com/')
      await page.waitForTimeout(5000)
   },15000)
})```


NO SE POR QUE PASA ESO Y SIGO TODOS LOS PASOS TAL CUAL 

Otra alternativa para hacer el --init con jest

npx jest --init

Les dejo mis apuntes por si alguien quieres tener los pasos para setear otros proyectos

Nota: el profesor no usa en el video @types/jest sin embargo yo lo coloco porque en mi caso si le doy uso

//Pasos para arracar el proyecto del framework de jest con puppeteer

  1. npm init -y

  2. git init

  3. npm i puppeteer jest jest-puppeteer @types/jest babel-jest @babel/core @babel/preset-env

  4. Crear .gitignore

  5. node_modules.bin\jest --init //–> Esto inicializa la config de jest (Windows 10)

  6. Respuestas:
    √ Would you like to use Jest when running “test” script in “package.json”? … yes
    √ Would you like to use Typescript for the configuration file? … no
    √ Choose the test environment that will be used for testing » node
    √ Do you want Jest to add coverage reports? … no
    √ Which provider should be used to instrument code for coverage? » babel
    √ Automatically clear mock calls, instances, contexts and results before every test? … no

  7. En jest.config.js, descomentar y colocar {bail: 5, preset: “jest-puppeteer”}

  8. Crear archivo jest-puppeteer.config.js y pegarle dentro:
    module.exports = {
    launch:{
    headless: false,
    slowMo:100,
    },
    browserContext: ‘default’,
    };

  9. Crear archivo de babel.config.js y pegarle dentro:
    module.exports = {
    presets: [
    [
    ’@babel/preset-env’,
    {
    targets: {
    node: ‘current’,
    },
    },
    ],
    ],
    };

  10. Crear carpeta de pruebas test

  11. Crear una prueba para probar que todo funcione correctamente