From 69cf5b2549a32997852f05956b67a710d5652948 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 8 Jun 2021 15:00:06 +0200 Subject: [PATCH] changesets: update @sucrase/plugin-jest changeset to include instructions for how to work around re-export issue Signed-off-by: Patrik Oldsberg --- .changeset/breezy-ways-try.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.changeset/breezy-ways-try.md b/.changeset/breezy-ways-try.md index d8c22ed8ed..15e831a673 100644 --- a/.changeset/breezy-ways-try.md +++ b/.changeset/breezy-ways-try.md @@ -23,3 +23,21 @@ In order to switch back to `ts-jest`, install `ts-jest@^26.4.3` as a dependency ``` Note that this will override the default jest transforms included with the `@backstage/cli`. + +It is possible that some test code needs a small migration as a result of this change, which stems from a difference in how `sucrase` and `ts-jest` transform module re-exports. + +Consider the following code: + +```ts +import * as utils from './utils'; + +jest.spyOn(utils, 'myUtility').mockReturnValue(3); +``` + +If the `./utils` import for example refers to an index file that in turn re-exports from `./utils/myUtility`, you would have to change the code to the following to work around the fact that the exported object from `./utils` ends up not having configurable properties, thus breaking `jest.spyOn`. + +```ts +import * as utils from './utils/myUtility'; + +jest.spyOn(utils, 'myUtility').mockReturnValue(3); +```