Entornos de desarrollo

1º DAM/DAW - Curso 2024-2025

User Tools

Site Tools


apuntes:testing

This is an old revision of the document!


Testing

Test unitarios

const expect = require('chai').expect;
const { getDaysFromNow, getDays} = require('../../dateUtils');
 
beforeAll(() => {
    jest.useFakeTimers();
    jest.setSystemTime(new Date('2025-02-13'));
});
 
afterAll(() => {
    jest.useRealTimers();
});
 
describe('dateUtils', () => {
    // TODO Añadir casos de prueba para la función getYearsFromNow
 
    it('getDaysFromNow', () => {
        let days = getDaysFromNow(new Date('2025-02-12'));
        expect(days).equal(1);
 
        days = getDaysFromNow(new Date('2025-01-13'));
        expect(days).equal(31);
    });
 
    it('getDays', () => {
        let days = getDays(new Date('2025-01-12'), new Date('2025-01-15'));
        expect(days).equal(3);
 
        days = getDays(new Date('2025-01-01'), new Date('2024-01-01'));
        expect(days).equal(366);
 
        days = getDays(new Date('2024-01-01'), new Date('2024-01-01'));
        expect(days).equal(0);
    });
});
. . .
"scripts": {
    "unit-test": "jest src/test/unit",
    . . .
. . .
santi@zenbook:$ npm install -g jest

Test de integración


© 2024 Santiago Faci

apuntes/testing.1742751244.txt.gz · Last modified: 2025/03/23 17:34 by Santiago Faci