-1

I'm trying to run a Unit test with Playwright on an imported function in react, but it's failing with an error completely unrelated to the actual test, and the test doesn't run.

import { expect, test } from '@playwright/test';
import TipStatus from '../../shared/enum/TipStatus';
import { calculateTipForPerson } from './TipForEmployeesRepository';

 test.describe('TipForEmployeesRepository.calculateTipForPerson()', () => {
    test('should calculate tip based on correct pensum and indicator when comment is null', () => {
        const correctPensum = 1000;
        const indicator = 20;
        const comment: TipStatus | null = null;


        const result = calculateTipForPerson(comment, correctPensum, indicator);

        expect(result).toEqual(Math.floor((correctPensum / 100) * indicator));
    });


    test('should return 0 when comment is not null', () => {
        const correctPensum = 1500;
        const indicator = 15;
        const comment: TipStatus = TipStatus.PERFORMANCE

        const result = calculateTipForPerson(comment, correctPensum, indicator);

        expect(result).toEqual(0);
    });

});

The following test fails with an error that I cannot understand.



Error: Module did not self-register: '\\?\C:\work\project-light\node_modules\msnodesqlv8\build\Release\sqlserverv8.node'.

at src\backend\services\DatabaseService.ts:1

1 | import sql, { ConnectionPool, ConnectionError } from 'mssql/msnodesqlv8';
    | ^
2 | import DatabaseConfigurationService from './database-properties/DatabaseConfigurationService';
3 | import Logger from '../util/Logger';
4 |

at C:\work\project-light\node_modules\msnodesqlv8\lib\connection.js:10:21
at Object.<anonymous> (C:\work\project-light\node_modules\msnodesqlv8\lib\connection.js:580:3)
at Object.<anonymous> (C:\work\project-light\node_modules\msnodesqlv8\lib\sql.js:22:12)
at Object.<anonymous> (C:\work\project-light\node_modules\mssql\lib\msnodesqlv8\connection-pool.js:3:19)
at Object.<anonymous> (C:\work\project-light\node_modules\mssql\lib\msnodesqlv8\index.js:4:24)
at Object.<anonymous> (C:\work\project-light\node_modules\mssql\msnodesqlv8.js:1:18)
at Object.<anonymous> (C:\work\project-light\src\backend\services\DatabaseService.ts:1:1)
at Object.<anonymous> (C:\work\project-light\src\backend\repositories\TipForEmployeesRepository.ts:7:1)
at Object.<anonymous> (C:\work\project-light\src\backend\repositories\TipForEmployeesRepository.spec.ts:3:1)

Without the imported function or placing it in the test file directly, the test runs fine.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
kevl
  • 1
  • 2
  • This error looks incomplete. The first line seems to be missing, the one that contains the actual error message. Can you [edit] the post to share the complete message? Thanks. – ggorlen Aug 24 '23 at 15:06
  • @ggorlen I fixed the post, the full error is showing now – kevl Aug 25 '23 at 06:50
  • Thanks. Did you check the existing posts for this error? [1](https://stackoverflow.com/questions/28486891/uncaught-error-module-did-not-self-register), [2](https://stackoverflow.com/questions/34964310/error-module-did-not-self-register), [3](https://stackoverflow.com/questions/39785097/error-module-did-not-self-register). If they did not work for you, please list which answers you tried and what their output was. – ggorlen Aug 25 '23 at 14:56
  • Does this answer your question? [Uncaught Error: Module did not self-register](https://stackoverflow.com/questions/28486891/uncaught-error-module-did-not-self-register) – ggorlen Aug 25 '23 at 14:59

0 Answers0