@japa/snapshot
Version:
Snapshot testing plugin for Japa
48 lines (44 loc) • 1.54 kB
JavaScript
import {
PluginContext
} from "./chunk-5UVLWMSF.js";
// src/integrations/expect.ts
import { expect } from "expect";
var expectMatchInlineSnapshot = function(value, inlineSnapshot) {
const snapshotManager = PluginContext.snapshotManager;
const testContext = PluginContext.currentTestContext;
if (!inlineSnapshot || PluginContext.shouldUpdateSnapshots()) {
snapshotManager.updateInlineSnapshot(testContext.test, value, "expect");
return { pass: true, message: () => "" };
}
const testData = snapshotManager.getInlineSnapshotTestData(
testContext.test,
value,
inlineSnapshot
);
return {
pass: testData.pass,
message: () => !testData.pass ? `Inline snapshot does not match:
${this.utils.diff(
testData.expected,
testData.received
)}` : ``
};
};
var expectMatchSnapshot = function(value) {
const snapshotManager = PluginContext.snapshotManager;
const testContext = PluginContext.currentTestContext;
if (snapshotManager.hasSnapshotInFile(testContext.test) || PluginContext.shouldUpdateSnapshots()) {
snapshotManager.updateFileSnapshot(testContext.test, value);
return { pass: true, message: () => "" };
}
const testData = snapshotManager.getFileSnapshotTestData(testContext.test, value);
return {
pass: testData.pass,
message: () => !testData.pass ? `Snapshot does not match:
${this.utils.diff(testData.expected, testData.received)}` : ``
};
};
expect.extend({
toMatchSnapshot: expectMatchSnapshot,
toMatchInlineSnapshot: expectMatchInlineSnapshot
});