Skip to content

Commit

Permalink
Add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed May 6, 2024
1 parent 9244f8b commit 8ba49b1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/server/fetchContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,35 @@ describe('fetchContent', () => {
timeout: timeout,
}));
});

it('should log warnings and errors', async () => {
jest.spyOn(console, 'warn').mockImplementation();
jest.spyOn(console, 'error').mockImplementation();
jest.spyOn(console, 'log').mockImplementation();
jest.spyOn(console, 'info').mockImplementation();

jest.mocked(loadContent).mockResolvedValue({
content: {
_component: 'component',
},
});

jest.mocked(getRequestContext).mockReturnValue(request);

await fetchContent<any, any>('slot-id');

const {logger} = jest.mocked(loadContent).mock.calls[0][1] as ResolvedFetchOptions;

expect(logger).toBeInstanceOf(FilteredLogger);

logger?.info('log');
logger?.debug('debug');

Check failure on line 255 in src/server/fetchContent.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected debug statement
logger?.warn('warning');
logger?.error('error');

expect(console.log).not.toHaveBeenCalled();

Check warning on line 259 in src/server/fetchContent.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
expect(console.info).not.toHaveBeenCalled();

Check warning on line 260 in src/server/fetchContent.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
expect(console.warn).toHaveBeenCalledWith('warning');

Check warning on line 261 in src/server/fetchContent.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
expect(console.error).toHaveBeenCalledWith('error');

Check warning on line 262 in src/server/fetchContent.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
});
});

0 comments on commit 8ba49b1

Please sign in to comment.