Skip to content

Commit 91dd267

Browse files
committed
test: complete test for initializer
1 parent 8d35ced commit 91dd267

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/theme-initializer.spec.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,47 @@ describe('ThemeInitializer', () => {
112112
it('should return early if no .slides elements', async () => {
113113
document.body.innerHTML = '';
114114

115-
await ThemeInitializer.init(mockOptions);
115+
try {
116+
await ThemeInitializer.init(mockOptions);
117+
} catch (e) {
118+
expect(e).toBeInstanceOf(Error);
119+
expect((e as Error).message).toBe('No slides found');
120+
}
121+
});
122+
it('should return early if no slidesFactory', async () => {
123+
document.body.innerHTML = '';
116124

117-
expect(Reveal.initialize).not.toHaveBeenCalled();
118-
expect(render).not.toHaveBeenCalled();
125+
try {
126+
// Use any here to force giving an incomplete parameters (method ask in javascript)
127+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
128+
await (ThemeInitializer as any).init({});
129+
} catch (e) {
130+
expect(e).toBeInstanceOf(Error);
131+
expect((e as Error).message).toBe('No slide factory function');
132+
}
119133
});
120134

135+
it('should init Reveal.js with correct default options even if there is just the slide factory', async () => {
136+
await ThemeInitializer.init({
137+
slidesFactory: mockSlidesFactory,
138+
});
139+
140+
expect(Reveal.initialize).toHaveBeenCalledWith(
141+
expect.objectContaining({
142+
controls: true,
143+
progress: true,
144+
history: true,
145+
center: false,
146+
width: 1920,
147+
height: 1080,
148+
slideNumber: 'c/t',
149+
showSlideNumber: 'speaker',
150+
showNotes: false,
151+
pdfMaxPagesPerSlide: 1,
152+
pdfSeparateFragments: true,
153+
})
154+
);
155+
});
121156
it('should init Reveal.js with correct default options', async () => {
122157
await ThemeInitializer.init(mockOptions);
123158

src/theme-initializer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ export const ThemeInitializer = {
6666
defaultSlidesType,
6767
slidesRenderer = defaultSlideRenderer,
6868
}: ThemeInitializerOptions) {
69+
if (!slidesFactory) {
70+
throw new Error('No slide factory function');
71+
}
72+
6973
const importSlideElement: HTMLElement | null =
7074
document.querySelector('.slides');
71-
if (importSlideElement == null) return;
75+
if (importSlideElement == null) throw new Error('No slides found');
7276

7377
// Retrieve the data type parameter to apply to a subset of slides
7478
const showType = getShowType(defaultSlidesType);

0 commit comments

Comments
 (0)