Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__test__/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`public api toBeValidDotAndMatchSnapshot 1`] = `"digraph g { a -> b; }"`;
exports[`public api toBeValidDotAndMatchSnapshot 1`] = `digraph g { a -> b; }`;

exports[`public api toMatchDotJsonSnapshot 1`] = `
Object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`toBeValidDotAndMatchSnapshot test matcher works 1`] = `"digraph g { a -> b; }"`;
exports[`toBeValidDotAndMatchSnapshot test matcher works 1`] = `digraph g { a -> b; }`;
24 changes: 24 additions & 0 deletions src/serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const raw = Symbol();

interface IWrapper {
[raw]: string;
}

function test(something: any): something is IWrapper {
return something && typeof something[raw] === 'string';
}

function print(wrapper: IWrapper): string {
return wrapper[raw];
}

export function wrap(value: string): IWrapper {
return { [raw]: value };
}

export const SnapshotSerializer: jest.SnapshotSerializerPlugin = {
test,
print,
};

expect.addSnapshotSerializer(SnapshotSerializer);
3 changes: 2 additions & 1 deletion src/to-be-valid-dot-and-match-snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { toMatchSnapshot } from 'jest-snapshot';
import { isValidDot } from './lib/is-valid-dot';
import { wrap } from './serializer';

export function toBeValidDotAndMatchSnapshotMatcher(this: any, dot: string): jest.CustomMatcherResult {
const result = isValidDot(dot);
if (result.pass) {
return toMatchSnapshot.call(this, dot);
return toMatchSnapshot.call(this, wrap(dot));
}
return result;
}
Expand Down