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

219
Visualizações
prueba unitaria para una función que no devuelve nada

Quiero escribir una prueba unitaria para la función loadingTime. Esta función convierte timeTable (tipo de mapa) en una matriz de resultados que consta de 0 y 1. Los índices 3-5 (03:00 - 05:00), 12-14 (12:00 - 14:00) son 1, el resto es 0. Luego, la matriz de resultados se asigna a la tabla de filas. ¿Cómo escribir una prueba unitaria para esto?

 timeTable: Map<number, Array<from: string to: string>> 0:[{from: "03:00", to: 05:00"}, {from: "12:00", to:"14:00"}] 1:[{from: "00:00", to: "23:00"}] 2:[{from: "00:00", to: "23:00"}] 3:[{from: "00:00", to: "23:00"}] 4:[{from: "00:00", to: "23:00"}] 5:[{from: "00:00", to: "23:00"}] 6:[{from: "00:00", to: "23:00"}]

tabla de filas:

 rowTable: Row[] = [ { name: this.allDays.monday, items: new Array(24).fill(1), active: true }, { name: this.allDays.tuesday, items: new Array(24).fill(1), active: true }, { name: this.allDays.wednesday, items: new Array(24).fill(1), active: true }, { name: this.allDays.thursday, items: new Array(24).fill(1), active: true }, { name: this.allDays.friday, items: new Array(24).fill(1), active: true }, { name: this.allDays.saturday, items: new Array(24).fill(1), active: true }, { name: this.allDays.sunday, items: new Array(24).fill(1), active: true } ];

Tiempo de carga

 loadingTime(): void { if (this.timeTable) { let result = [...this.timeTable].reduce((r, [key, value], i) => { r[i] = Array(24).fill(0); value.forEach(o => { let start = getHours(o.from); const end = getHours(o.to); while (start <= end) { r[i][start] = 1; start++; } }) return r; }, []); this.rowTable.forEach((el, i) => { el.items = result[i]; el.active = false; }) } }

mis intentos, pero no sé si voy en la dirección correcta. Por favor ayuda

 it("should loading Time"), () => { const timetableMock = new Map<number, Array<from: string to: string>>() timetableMock.set(0, [{ from: '00:00', to: '23:00' }]); component.loadingTime = () => {}; const onSaveSpy = spyOn(component, "loadingTime") component.loadingTime(); expect(onSaveSpy).toEqual([........I don't know what to enter here]); }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

¿Funcionará algo como esto?

 it('loadingTime should not update rowTable if timeTable is undefined', () => { const rowTableForEachSpy = jest.spyOn(component.rowTable, 'forEach'); component.timeTable = void 0; component.loadingTime(); expect(rowTableForEachSpy).not.toHaveBeenCalled(); // in addition you can most probably assert `component.rowTable` value here }) it('loadingTime should update rowTable if timeTable is defined', () => { const rowTableForEachSpy = jest.spyOn(component.rowTable, 'forEach'); component.timeTable = new Map(...); component.loadingTime(); expect(rowTableForEachSpy).toHaveBeenCalled(); // in addition you can most probably assert `component.rowTable` value here })
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