okay so I have code that looks like this:
import { wait } from "@testing-library/react";
describe("MyTest", () => {
it("should wait", async () => {
await wait(() => {
console.log("Done");
});
});
});
I want to change that import member wait
to be waitFor
. I'm able to change it in the AST like so:
source
.find(j.ImportDeclaration)
.filter((path) => path.node.source.value === "@testing-library/react")
.find(j.ImportSpecifier)
.filter((path) => path.node.imported.name === "wait")
.replaceWith(j.importSpecifier(j.identifier("waitFor")))
.toSource()
However, the outputed code will look as follows:
import { waitFor } from "@testing-library/react";
describe("MyTest", () => {
it("should wait", async () => {
await wait(() => {
console.log("Done");
});
});
});
I'm looking for a way to change all subsequent usages of that import to match the new name
Is this possible with jscodeshift?