Skip to content

Commit

Permalink
feat: support custom literal tag on inlineSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 10, 2022
1 parent 6772c5f commit 2623543
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -72,7 +72,7 @@ function prepareSnapString(snap: string, source: string, index: number) {
: `${quote}\n${lines.map(i => indentNext + i).join('\n').replace(/`/g, '\\`')}\n${indent}${quote}`
}

const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(['"`\)])/m
const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*[\w_$]*(['"`\)])/m
export function replaceInlineSnap(code: string, s: MagicString, index: number, newSnap: string) {
const startMatch = startRegex.exec(code.slice(index))
if (!startMatch)
Expand Down
19 changes: 19 additions & 0 deletions test/core/test/snapshot-inline.test.ts
Expand Up @@ -87,3 +87,22 @@ test('properties inline snapshot', () => {
}
`)
})

test('literal tag', () => {
const html = String.raw
const text = `
<body>
<h1>My First Heading.</h1>
<p>My first paragraph.</p>
</body>
`

expect(text).toMatchInlineSnapshot(html`
"
<body>
<h1>My First Heading.</h1>
<p>My first paragraph.</p>
</body>
"
`)
})

0 comments on commit 2623543

Please sign in to comment.