first
This commit is contained in:
54
jest.setup.js
Normal file
54
jest.setup.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// Configuração para adicionar suporte a testes com React e hooks
|
||||
require('@testing-library/jest-dom');
|
||||
|
||||
// Mock para evitar erros relacionados ao Next.js Image
|
||||
jest.mock('next/image', () => ({
|
||||
__esModule: true,
|
||||
default: (props) => {
|
||||
// eslint-disable-next-line jsx-a11y/alt-text
|
||||
return { type: 'img', props };
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock do localStorage e sessionStorage para testes
|
||||
class LocalStorageMock {
|
||||
constructor() {
|
||||
this.store = {};
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.store = {};
|
||||
}
|
||||
|
||||
getItem(key) {
|
||||
return this.store[key] || null;
|
||||
}
|
||||
|
||||
setItem(key, value) {
|
||||
this.store[key] = String(value);
|
||||
}
|
||||
|
||||
removeItem(key) {
|
||||
delete this.store[key];
|
||||
}
|
||||
}
|
||||
|
||||
global.localStorage = new LocalStorageMock();
|
||||
global.sessionStorage = new LocalStorageMock();
|
||||
|
||||
// Mock global fetch
|
||||
global.fetch = jest.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
})
|
||||
);
|
||||
|
||||
// Suprimir warnings do console nos testes
|
||||
global.console = {
|
||||
...console,
|
||||
// Uncomment to ignore specific console methods during tests
|
||||
// log: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
};
|
||||
Reference in New Issue
Block a user