Skip to content

Commit 600b2c0

Browse files
TheJaredWilcurteddyerburgh
authored andcommittedJan 20, 2020
feat: automatically remove data-test attributes from snapshots (#16)
BREAKING_CHANGE: remove data-test attributes from snapshots
1 parent 401e2b9 commit 600b2c0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ const isVueWrapper = received => (
66
typeof received === 'object' &&
77
typeof received.isVueInstance === 'function'
88
)
9+
const removeServerRenderedText = html => html.replace(/ data-server-rendered="true"/, '')
10+
// [-\w]+ will catch 1 or more instances of a-z, A-Z, 0-9, hyphen (-), or underscore (_)
11+
const removeDataTestAttributes = html => html.replace(/ data-test="[-\w]+"/g, '')
912

1013
module.exports = {
1114
test (received) {
1215
return isHtmlString(received) || isVueWrapper(received)
1316
},
1417
print (received) {
15-
const html = (isVueWrapper(received) ? received.html() : received) || ''
16-
const removedServerRenderedText = html.replace(/ data-server-rendered="true"/, '')
17-
return beautify(removedServerRenderedText, { indent_size: 2 })
18+
let html = (isVueWrapper(received) ? received.html() : received) || ''
19+
html = removeServerRenderedText(html)
20+
html = removeDataTestAttributes(html)
21+
return beautify(html, { indent_size: 2 })
1822
}
1923
}

0 commit comments

Comments
 (0)
Please sign in to comment.