Skip to content

Commit fea63cf

Browse files
author
Frazer Smith
committed
test: add pdfImages function tests
1 parent aa0c482 commit fea63cf

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/index.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,73 @@ describe('pdfFonts function', () => {
255255
});
256256
});
257257

258+
describe('pdfImages function', () => {
259+
afterAll(async () => {
260+
await clean();
261+
});
262+
263+
test('Should accept options and list all images in file', async () => {
264+
const poppler = new Poppler();
265+
const options = {
266+
list: true
267+
};
268+
269+
await poppler
270+
.pdfImages(options, file)
271+
.then((res) => {
272+
expect(typeof res).toBe('string');
273+
});
274+
});
275+
276+
test('Should return an Error object if file passed not PDF format', async () => {
277+
const poppler = new Poppler();
278+
const testTxtFile = `${testDirectory}test.txt`;
279+
280+
expect.assertions(1);
281+
await poppler.pdfImages(undefined, testTxtFile).catch((err) => {
282+
expect(err.message.substring(0, 15)).toBe('Command failed:');
283+
});
284+
});
285+
286+
test('Should return an Error object if PDF file missing', async () => {
287+
const poppler = new Poppler();
288+
289+
expect.assertions(1);
290+
await poppler.pdfImages(undefined, undefined).catch((err) => {
291+
expect(err.message.substring(0, 15)).toBe('Command failed:');
292+
});
293+
});
294+
295+
test('Should return an Error object if invalid value types provided for an option are passed to function', async () => {
296+
const poppler = new Poppler();
297+
const options = {
298+
firstPageToConvert: 'test',
299+
lastPageToConvert: 'test'
300+
};
301+
302+
expect.assertions(1);
303+
await poppler.pdfImages(options, undefined).catch((err) => {
304+
expect(err.message).toEqual(
305+
"Invalid value type provided for option 'firstPageToConvert', expected number but recieved string"
306+
);
307+
});
308+
});
309+
310+
test('Should return an Error object if invalid option is passed to function', async () => {
311+
const poppler = new Poppler();
312+
const options = {
313+
middlePageToConvert: 'test'
314+
};
315+
316+
expect.assertions(1);
317+
await poppler.pdfImages(options, undefined).catch((err) => {
318+
expect(err.message).toEqual(
319+
"Invalid option provided 'middlePageToConvert'"
320+
);
321+
});
322+
});
323+
});
324+
258325
describe('pdfInfo function', () => {
259326
afterAll(async () => {
260327
await clean();

0 commit comments

Comments
 (0)