#7058 LeftMenu vitest #1153

Open
jsegarra wants to merge 18 commits from 7058_leftMenu_vitest into dev
1 changed files with 43 additions and 1 deletions
Showing only changes of commit 42f113ccf6 - Show all commits

View File

@ -132,6 +132,48 @@ function mount(source) {
return wrapper;
}
describe('getRoutes', () => {
afterEach(() => vi.clearAllMocks());
const getRoutes = vi.fn().mockImplementation((props, getMethodA, getMethodB) => {
const handleRoutes = {
methodA: getMethodA,
methodB: getMethodB,
};
try {
handleRoutes[props.source]();
} catch (error) {
throw Error('Method not defined');
}
});
const getMethodA = vi.fn();
const getMethodB = vi.fn();
const fn = (props) => getRoutes(props, getMethodA, getMethodB);
it('should call getMethodB when source is card', () => {
let props = { source: 'methodB' };
fn(props);
expect(getMethodB).toHaveBeenCalled();
expect(getMethodA).not.toHaveBeenCalled();
});
it('should call getMethodA when source is main', () => {
let props = { source: 'methodA' };
fn(props);
expect(getMethodA).toHaveBeenCalled();
expect(getMethodB).not.toHaveBeenCalled();
});
//WIP
it('should call getMethodA when source is main', () => {
let props = { source: 'methodC' };
Review

Poner otro nombre, está repetido.

Poner otro nombre, está repetido.
Review

oh vaya

oh vaya
Review

should not call getMethodA when method is undefined por ej.

should not call getMethodA when method is undefined por ej.
expect(fn(props)).toThrowError('Method not defined');
expect(getMethodA).not.toHaveBeenCalled();
expect(getMethodB).not.toHaveBeenCalled();
});
});
describe('Leftmenu as card', () => {
beforeAll(() => {
vm = mount('card').vm;
@ -335,7 +377,7 @@ describe.only('addChildren', () => {
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
});
it.only('should not add menu items if no matches are found', () => {
it('should not add menu items if no matches are found', () => {
const module = 'testModule';
const route = {
meta: { menu: 'child3', menuChildren: [] },