From 7d92ce9ef67cd44aca5707cbf4f268b26605c983 Mon Sep 17 00:00:00 2001 From: Andrei Picus Date: Tue, 13 Jun 2023 10:37:43 +0200 Subject: [PATCH] feat: Improve `willCapture` diff --- src/expectation/it.ts | 1 + src/expectation/matcher.spec.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/expectation/it.ts b/src/expectation/it.ts index c2f3c09..0678864 100644 --- a/src/expectation/it.ts +++ b/src/expectation/it.ts @@ -283,6 +283,7 @@ const willCapture = ( return true; }, toJSON: () => name ?? 'captures', + getDiff: (actual) => ({ actual, expected: actual }), get value(): T | undefined { return capturedValue; }, diff --git a/src/expectation/matcher.spec.ts b/src/expectation/matcher.spec.ts index 9d312db..c39281f 100644 --- a/src/expectation/matcher.spec.ts +++ b/src/expectation/matcher.spec.ts @@ -626,5 +626,17 @@ describe('It', () => { expect(It.willCapture().toJSON()).toEqual('captures'); expect(It.willCapture('custom').toJSON()).toEqual('custom'); }); + + it('should print diff', () => { + expect(It.willCapture().getDiff('foo')).toEqual({ + actual: 'foo', + expected: 'foo', + }); + + expect(It.willCapture('captor').getDiff('foo')).toEqual({ + actual: 'foo', + expected: 'foo', + }); + }); }); });