TypeScript Unit Tests: Access `private` Members

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • Zigi - Delete the most useless function ever: context switching.
  • Scout APM - Truly a developer’s best friend
  • Sonar - Write Clean JavaScript Code. Always.
  • InfluxDB - Build time-series-based applications quickly and at scale.
  • TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    But there is a caveat: jest.spy(inst, "_privateMethod") will not work, because TypeScript enforces that only public methods are spied on. The simplest workaround is to cast inst as any. Until there is a Utility Type that treats all members als public. As already suggested.

  • Zigi

    Delete the most useless function ever: context switching.. Zigi monitors Jira and GitHub updates, pings you when PRs need approval and lets you take fast actions - all directly from Slack! Plus it reduces cycle time by up to 75%.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts