Test querySelectorAll call

pull/28788/head^2
Florian Duros 2022-09-28 15:25:16 +02:00
parent fe14847bb9
commit b2c2ef2bd6
No known key found for this signature in database
GPG Key ID: 9700AA5870258A0B
1 changed files with 5 additions and 1 deletions

View File

@ -21,6 +21,8 @@ describe('theme', () => {
let lightTheme; let lightTheme;
let darkTheme; let darkTheme;
let spyQuerySelectorAll: jest.MockInstance<NodeListOf<Element>, [selectors: string]>;
beforeEach(() => { beforeEach(() => {
const styles = [ const styles = [
{ {
@ -48,7 +50,7 @@ describe('theme', () => {
darkTheme = styles[1]; darkTheme = styles[1];
jest.spyOn(document.body, 'style', 'get').mockReturnValue([] as any); jest.spyOn(document.body, 'style', 'get').mockReturnValue([] as any);
jest.spyOn(document, 'querySelectorAll').mockReturnValue(styles as any); spyQuerySelectorAll = jest.spyOn(document, 'querySelectorAll').mockReturnValue(styles as any);
}); });
afterEach(() => { afterEach(() => {
@ -64,6 +66,8 @@ describe('theme', () => {
}); });
// Then // Then
expect(spyQuerySelectorAll).toHaveBeenCalledWith('[data-mx-theme]');
expect(spyQuerySelectorAll).toBeCalledTimes(1);
expect(lightTheme.disabled).toBe(false); expect(lightTheme.disabled).toBe(false);
expect(darkTheme.disabled).toBe(true); expect(darkTheme.disabled).toBe(true);
}); });