Wondering what’s next for npm?Check out our public roadmap! »

    chai-pdf

    1.0.9 • Public • Published

    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);
    

    Install

    npm i chai-pdf

    DownloadsWeekly Downloads

    25

    Version

    1.0.9

    License

    MIT

    Unpacked Size

    1.5 MB

    Total Files

    14

    Last publish

    Collaborators

    • avatar