Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function compareSnapshot(expect, flags, subjectAdapter, subjectRenderer, subjectOutput) {
const state = matchers.getState();
if (!state.unexpectedSnapshot) {
state.unexpectedSnapshot = new UnexpectedSnapshotState(state.snapshotState);
}
const snapshot = state.unexpectedSnapshot.getSnapshot(state.testPath, state.currentTestName, expect);
if (snapshot === null) {
// Write and save
state.unexpectedSnapshot.saveSnapshot(state.testPath, state.currentTestName, rawAdapter.serialize(subjectAdapter, subjectOutput), expect);
state.snapshotState.added++;
} else {
expect.withError(() => {
if (flags.satisfy) {
expect(subjectRenderer, 'to have rendered', rawAdapter.deserialize(snapshot));
} else {
expect(subjectRenderer, 'to have rendered with all children with all wrappers with all classes with all attributes', rawAdapter.deserialize(snapshot));
snapshotState.removeUncheckedKeys = function () {
const state = matchers.getState();
let isDirty = false;
const snapshot = state.unexpectedSnapshot && state.unexpectedSnapshot._files[state.testPath];
if (snapshot && snapshot.uncheckedKeys.size) {
snapshot.uncheckedKeys.forEach(key => {
const testName = /(.*)\s[0-9]+$/.exec(key)[1];
if (!snapshot.failedTests.has(testName)) {
isDirty = true;
delete snapshot.allTests[key]
}
});
}
if (!snapshot || Object.keys(snapshot.allTests).length === 0) {
const snapshotPath = getSnapshotPath(state.testPath);
try {
function injectStateHooks() {
const state = matchers.getState();
const snapshotState = state && state.snapshotState;
if (snapshotState) {
const originalRemoveUncheckedKeys = snapshotState.removeUncheckedKeys;
snapshotState.removeUncheckedKeys = function () {
const state = matchers.getState();
let isDirty = false;
const snapshot = state.unexpectedSnapshot && state.unexpectedSnapshot._files[state.testPath];
if (snapshot && snapshot.uncheckedKeys.size) {
snapshot.uncheckedKeys.forEach(key => {
const testName = /(.*)\s[0-9]+$/.exec(key)[1];
if (!snapshot.failedTests.has(testName)) {
isDirty = true;
delete snapshot.allTests[key]
}