web-components
web-components copied to clipboard
TypeScript: investigate converting tests that use private API
It's quite simple to convert our tests to use TypeScript, as demonstrated here.
const { esbuildPlugin } = require('@web/dev-server-esbuild');
module.exports = {
nodeResolve: true,
plugins: [
esbuildPlugin({ ts: true })
]
};
However, we are using protected and private APIs in many tests, which becomes problematic when converting them to TS.
One possible option would be to create shared helpers for all of those, so we only have @ts-expect-error there.
To use private API in the tests, we can either use
Casting to any
(grid as any)._isExpanded('foo');
Or defining a test type for the Private API:
type GridElementWithInternalAPI<ItemType> = Grid<ItemType> & {
_isExpanded(item: ItemType): boolean;
};
return (grid as GridElementWithInternalAPI<string>)._isExpanded('foo');