Skip to content

Commit

Permalink
Mock jspdf version in snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Sep 25, 2024
1 parent f37ba46 commit 73c5117
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
Binary file modified tests/pdf_snapshots/long_comment.pdf
Binary file not shown.
Binary file modified tests/pdf_snapshots/medium_comment.pdf
Binary file not shown.
Binary file modified tests/pdf_snapshots/short_comment.pdf
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/snapshot_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { DocController, FlatSurvey, IDocOptions, IPdfBrick } from '../src/entrie
import { SurveyPDFTester, TestHelper } from '../src/helper_test';
import { SurveyPDF } from '../src/survey';
import { readFileSync, writeFileSync } from 'fs';

import jsPDF from 'jspdf';
interface IPDFSnapshotOptions {
snapshotName: string;
controllerOptions?: IDocOptions;
onSurveyCreated?: (survey: SurveyPDF) => void;
}

export async function checkPDFSnapshot(surveyJSON: any, snapshotOptions: IPDFSnapshotOptions): Promise<void> {
const jsPdfVersion = jsPDF.version;
jsPDF.version = 'test';
const survey = new SurveyPDFTester(surveyJSON, snapshotOptions.controllerOptions ?? TestHelper.defaultOptions);
snapshotOptions.onSurveyCreated && snapshotOptions.onSurveyCreated(survey);
survey.onDocControllerCreated.add((_, options) => {
Expand All @@ -26,6 +28,7 @@ export async function checkPDFSnapshot(surveyJSON: any, snapshotOptions: IPDFSna
const expected = readFileSync(fileName);
expect(actual, `snapshot: "${snapshotName}" did not match`, { showMatcherMessage: false }).toEqual(expected);
}
jsPDF.version = jsPdfVersion;
}

interface IFlatSnaphotOptions {
Expand Down

0 comments on commit 73c5117

Please sign in to comment.