From 3e4f170bb69d09fa38ae6b2b301e726252a0ecf4 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sun, 9 Jan 2022 20:12:40 +1300 Subject: [PATCH] test(type-utils): add test for IndexSignature internals --- .../type-utils/tests/isTypeReadonly.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/type-utils/tests/isTypeReadonly.test.ts b/packages/type-utils/tests/isTypeReadonly.test.ts index d757c59869d1..751da80471f4 100644 --- a/packages/type-utils/tests/isTypeReadonly.test.ts +++ b/packages/type-utils/tests/isTypeReadonly.test.ts @@ -177,5 +177,31 @@ describe('isTypeReadonly', () => { }); }); }); + + describe('IndexSignature', () => { + describe('is readonly', () => { + it('handles readonly PropertySignature inside a readonly IndexSignature', () => { + const { type, checker } = getType( + `type Test = { readonly [key: string]: { readonly foo: readonly string[]; }; };`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(true); + }); + }); + + describe('is not readonly', () => { + describe('default options', () => { + it('fails with a mutable PropertySignature inside a readonly IndexSignature', () => { + const { type, checker } = getType( + `type Test = { readonly [key: string]: { foo: string[]; }; };`, + ); + + const result = isTypeReadonly(checker, type); + expect(result).toBe(false); + }); + }); + }); + }); }); });