Repository: jestjs/jest (TypeScript)

Issue:
[Bug]: Inline snapshots are appending a new template literal instead of replacing existing string
### Version

29.6.4

### Steps to reproduce

1. Clone https://github.com/bawjensen/jest-inline-snapshot-repro
2. `pnpm install`
3. `pnpm jest inline-snapshot.test.js --updateSnapshot` (though I had to run `pnpm jest inline-snapshot.test.js --updateSnapshot --prettierPath ''` perhaps due to quirks in my path having `prettier` on it)
4. Observe the diff in `inline-snapshot.test.js`

### Expected behavior

I see

```diff
 test("a failing inline snapshot will append, not overwrite as desired", () => {
-  expect("expected string").toMatchInlineSnapshot('"incorrect string"');
+  expect("expected string").toMatchInlineSnapshot(`"expected string"`);
 });
```

### Actual behavior

I see

```diff
 test("a failing inline snapshot will append, not overwrite as desired", () => {
-  expect("expected string").toMatchInlineSnapshot('"incorrect string"');
+  expect("expected string").toMatchInlineSnapshot('"incorrect string"', `"expected string"`);
 });
```

### Additional context

Our single-line template literals are being rewritten with single quotes due to our usage of the `quotes` eslint rule, thus we run into this issue.

I believe that I've traced the issue to https://github.com/jestjs/jest/blob/f2c78d04ff35688571a66d66c8a2c7c17a095444/packages/jest-snapshot/src/InlineSnapshots.ts#L277, and can confirm in my setup that patching this with

```diff
       const snapshotIndex = args.findIndex(
-        ({type}) => type === 'TemplateLiteral'
+        ({type}) => type === 'TemplateLiteral' || type === 'StringLiteral'
       );
```

fixes the issue. I'll be pushing up a PR soon with that proposed fix.

### Environment

```shell
System:
    OS: macOS 13.5.1
    CPU: (10) x64 Apple M1 Max
  Binaries:
    Node: 16.17.1 - ~/src/coda/build/node/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.15.0 - ~/src/coda/build/node/bin/npm
    pnpm: 8.6.5 - ~/src/coda/build/node/bin/pnpm
  npmPackages:
    jest: ^29.6.4 => 29.6.4
```



Hints:
From what I can tell this is the same as #10164, which was closed due to inactivity but seemed like a valid issue

Patch:
diff --git a/packages/jest-snapshot/src/InlineSnapshots.ts b/packages/jest-snapshot/src/InlineSnapshots.ts
--- a/packages/jest-snapshot/src/InlineSnapshots.ts
+++ b/packages/jest-snapshot/src/InlineSnapshots.ts
@@ -274,7 +274,7 @@ const traverseAst = (
     snapshotMatcherNames.push(callee.property.name);
 
     const snapshotIndex = args.findIndex(
-      ({type}) => type === 'TemplateLiteral',
+      ({type}) => type === 'TemplateLiteral' || type === 'StringLiteral',
     );
 
     const {snapshot} = inlineSnapshot;


Test patch:
diff --git a/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts b/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
--- a/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
+++ b/packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
@@ -738,3 +738,23 @@ test('saveInlineSnapshots() prioritize parser from project/editor configuration'
       '});\n',
   );
 });
+
+test('saveInlineSnapshots() replaces string literal, not just template literal', () => {
+  const filename = path.join(dir, 'my.test.js');
+  fs.writeFileSync(filename, 'expect("a").toMatchInlineSnapshot("b");\n');
+
+  saveInlineSnapshots(
+    [
+      {
+        frame: {column: 13, file: filename, line: 1} as Frame,
+        snapshot: 'a',
+      },
+    ],
+    dir,
+    'prettier',
+  );
+
+  expect(fs.readFileSync(filename, 'utf-8')).toBe(
+    'expect("a").toMatchInlineSnapshot(`a`);\n',
+  );
+});