From 44b3b773b99f29eabc4d683509de39bdd68796ce Mon Sep 17 00:00:00 2001 From: Ahn <27772165+ahnpnl@users.noreply.github.com> Date: Mon, 8 Nov 2021 21:35:21 +0100 Subject: [PATCH] fix(serializers): revert partially changes in `ng-snapshot` (#1150) Closes #1148 --- src/__tests__/ng-snapshot.spec.ts | 11 +++++++++++ src/serializers/ng-snapshot.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/ng-snapshot.spec.ts diff --git a/src/__tests__/ng-snapshot.spec.ts b/src/__tests__/ng-snapshot.spec.ts new file mode 100644 index 0000000000..0f08e99814 --- /dev/null +++ b/src/__tests__/ng-snapshot.spec.ts @@ -0,0 +1,11 @@ +import ngSnapshot from '../serializers/ng-snapshot'; + +describe('ng-snapshot', () => { + test('should return true when matching the condition', () => { + expect(ngSnapshot.test({ componentRef: 'foo' })).toBe(true); + }); + + test.each([undefined, null, 1, {}])('should return false when not matching the condition', (value) => { + expect(ngSnapshot.test(value)).toBe(false); + }); +}); diff --git a/src/serializers/ng-snapshot.ts b/src/serializers/ng-snapshot.ts index 928ae27575..8f6ea3772b 100644 --- a/src/serializers/ng-snapshot.ts +++ b/src/serializers/ng-snapshot.ts @@ -101,7 +101,7 @@ const print = (fixture: unknown, print: Printer, indent: Indent, opts: PluginOpt // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types const test = (val: any): boolean => - typeof val === 'object' && Object.prototype.hasOwnProperty.call(val, 'componentRef'); + !!val && typeof val === 'object' && Object.prototype.hasOwnProperty.call(val, 'componentRef'); export = { print,