Skip to content

Commit

Permalink
test(type-utils): add test for IndexSignature internals
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jan 10, 2022
1 parent bb209f4 commit 8906f67
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/type-utils/tests/isTypeReadonly.test.ts
Expand Up @@ -109,6 +109,32 @@ describe('isTypeReadonly', () => {
])('handles non fully readonly sets and maps', runTests);
});
});

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);
});
});
});
});
});

describe('treatMethodsAsReadonly', () => {
Expand Down

0 comments on commit 8906f67

Please sign in to comment.