Skip to content

Commit

Permalink
chore(edit-content): fix errors with testing #30215
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Nov 20, 2024
1 parent 82c15d7 commit 2a0acf4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion core-web/libs/edit-content/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export default {
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment'
]
],
testEnvironment: '@happy-dom/jest-environment'
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ import { TREE_SELECT_MOCK, TREE_SELECT_SITES_MOCK } from '../../../../../utils/m

describe('SelectExisingFileStore', () => {
let store: InstanceType<typeof SelectExisingFileStore>;
let service: SpyObject<DotEditContentService>;
let editContentService: SpyObject<DotEditContentService>;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [SelectExisingFileStore, mockProvider(DotEditContentService)]
providers: [
SelectExisingFileStore,
mockProvider(DotEditContentService, {
getSitesTreePath: jest.fn().mockReturnValue(of(TREE_SELECT_SITES_MOCK)),
getContentByFolder: jest.fn().mockReturnValue(of([]))
})
]
});

store = TestBed.inject(SelectExisingFileStore);
service = TestBed.inject(DotEditContentService) as SpyObject<DotEditContentService>;
editContentService = TestBed.inject(
DotEditContentService
) as SpyObject<DotEditContentService>;
});

it('should be created', () => {
Expand All @@ -30,7 +38,7 @@ describe('SelectExisingFileStore', () => {

describe('Method: loadFolders', () => {
it('should set folders status to LOADING and then to LOADED with data', fakeAsync(() => {
service.getSitesTreePath.mockReturnValue(of(TREE_SELECT_SITES_MOCK));
editContentService.getSitesTreePath.mockReturnValue(of(TREE_SELECT_SITES_MOCK));

store.loadFolders();

Expand All @@ -41,7 +49,7 @@ describe('SelectExisingFileStore', () => {
}));

it('should set folders status to ERROR on service error', fakeAsync(() => {
service.getSitesTreePath.mockReturnValue(throwError('error'));
editContentService.getSitesTreePath.mockReturnValue(throwError('error'));

store.loadFolders();

Expand All @@ -56,7 +64,7 @@ describe('SelectExisingFileStore', () => {
it('should load children for a node', fakeAsync(() => {
const mockChildren = [...TREE_SELECT_SITES_MOCK];

service.getFoldersTreeNode.mockReturnValue(of(mockChildren));
editContentService.getFoldersTreeNode.mockReturnValue(of(mockChildren));

const node = { ...TREE_SELECT_MOCK[0] };

Expand All @@ -76,7 +84,7 @@ describe('SelectExisingFileStore', () => {
}));

it('should handle error when loading children', fakeAsync(() => {
service.getFoldersTreeNode.mockReturnValue(throwError('error'));
editContentService.getFoldersTreeNode.mockReturnValue(throwError('error'));

const node = { ...TREE_SELECT_MOCK[0], children: [] };

Expand Down
10 changes: 0 additions & 10 deletions core-web/libs/edit-content/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
import 'jest-preset-angular/setup-jest';

// Workaround for the following issue:
// https://github.com/jsdom/jsdom/issues/2177#issuecomment-1724971596
const originalConsoleError = console.error;
const jsDomCssError = 'Error: Could not parse CSS stylesheet';
console.error = (...params) => {
if (!params.find((p) => p.toString().includes(jsDomCssError))) {
originalConsoleError(...params);
}
};

0 comments on commit 2a0acf4

Please sign in to comment.