es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Tag: JESTJS

Probando la función sleep de JavaScript utilizando Jest.

Tengo esta función: function sleep(milliseconds) { return new Promise((resolve) => { setTimeout(resolve, milliseconds); }); } Básicamente esta función retrasa la lógica, por ejemplo: function sleep(milliseconds) { return new Promise((resolve) => { setTimeout(resolve, milliseconds); }); } async function delayedGreeting() { console.log("Hola"); await sleep(2000); //esperará 2 segundos y luego mostrará el siguiente . . . Read more

El Jest mock no cubre el código como se esperaba.

Estoy tratando de cubrir la siguiente función con la prueba unitaria de Jest. export const submitCampaignForm = ( formData: IFormContextValues, mutate: (formData: IFormContextValues, setCamapignId: any) => void, setCamapignId: (val: string) => void, ): void => { mutate(formData, { onSuccess: (data: ICampaignResponse) => { if (data.id) { setCamapignId(data.id); } }, }); . . . Read more

Pruebas unitarias Jest para Cron

// Cómo escribir casos de prueba unitarios para la siguiente tarea cron index.js import cron from ‘node-cron’ export const cronJob = cron.schedule(pattern, async() => { // hacer algo } index.spec.js import { cron } from ‘node-cron’; import {cronJob} from ‘.’; jest.mock(‘node-cron’, () => { return { schedule: jest.fn(), }; }); . . . Read more

Error de sintaxis – node_modules/react-native/Libraries/polyfills/error-guard.js: Falta un punto y coma. (14:4) al ejecutar Jest en la biblioteca de React Native.

Estoy tratando de configurar jest para una biblioteca de React Native, pero estoy obteniendo el siguiente error: SyntaxError: react-native/Libraries/polyfills/error-guard.js: Falta un punto y coma. (14: 4) “` react-native version: 0.61.5 app.js import { NativeModules } from ‘react-native’; import { Dimensions } from ‘react-native’; function sum(a, b) { return a + . . . Read more