From f9e8c441cf253a8811d2a0987707b4118004a495 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Mon, 16 May 2022 10:20:27 +0200 Subject: [PATCH] feat(eslint-plugin): added more test cases for prefer-nullish-coalescing rule --- .../rules/prefer-nullish-coalescing.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts b/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts index b5094608dab1..3f061ffd8573 100644 --- a/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts @@ -77,6 +77,7 @@ x ?? 'foo'; }, ...[ + 'x !== undefined && x !== null ? "foo" : "bar";', 'x !== null && x !== undefined && x !== 5 ? x : y', 'x === null || x === undefined || x === 5 ? x : y', 'x === undefined && x !== null ? x : y;', @@ -95,6 +96,10 @@ x ?? 'foo'; 'null != x ? y : x;', 'undefined != x ? y : x;', ` +declare const x: string | null; +x === undefined ? x : y; + `, + ` declare const x: string | undefined | null; x !== undefined ? x : y; `, @@ -102,6 +107,18 @@ x !== undefined ? x : y; declare const x: string | undefined | null; x !== null ? x : y; `, + ` +declare const x: string | null | any; +x === null ? x : y; + `, + ` +declare const x: string | null | unknown; +x === null ? x : y; + `, + ` +declare const x: string | undefined; +x === null ? x : y; + `, ].map(code => ({ code: code.trim(), options: [{ ignoreTernaryTests: false }] as const,