chai-pdf
v1.0.9
Published
Awesome chai plugin for testing PDF files
Downloads
9,490
Maintainers
Readme
chai-pdf
Awesome chai plugin for testing PDF files
Setup
Install the following system dependencies
Install npm module
npm install chai-pdf
Folder Structure
Place your actual and baseline pdfs inside the following folders:
- /data/actualPdfs
- /data/baselinePdfs
Usage
// Using BDD style "expect"
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-pdf'));
// Compare Pdfs by just indicating their filenames (with or without extension)
await expect("ActualPdfFilename").to.be.samePdfAs("ExpectedPdfFilename")
// You can also add options such as page masking
let options = {
masks: [
{ pageIndex: 1, coordinates: { x0: 35, y0: 70, x1: 145, y1: 95 } }
]
}
await expect("ActualPdfFilename.pdf").to.be.samePdfAs("ExpectedPdfFilename.pdf", options);
// Using BDD style "should"
const chai = require("chai");
const should = chai.should();
chai.use(require("../src/chaiPdf"));
let actualFileName = "maskedSame.pdf";
let baselineFileName = "baseline.pdf";
let options = {
masks: [{ pageIndex: 1, coordinates: { x0: 35, y0: 70, x1: 145, y1: 95 } }]
};
await actualFileName.should.be.samePdfAs(baselineFileName, options);