Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Qingggggggg committed Aug 26, 2022
1 parent a841e9d commit f6a55e1
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts
Expand Up @@ -36,14 +36,14 @@ describe('babel-restore-jsx', () => {

it('should handle props without children', () => {
expect(jsx('React.createElement("h1", {hi: there})')).toMatchInlineSnapshot(
`"<h1 hi={there} />;"`
'"<h1 />;"'
)
expect(
jsx('React.createElement("h2", {"hi": there})')
).toMatchInlineSnapshot(`"<h2 hi={there} />;"`)
).toMatchInlineSnapshot('"<h2 />;"')
expect(
jsx('React.createElement("h3", {hi: "there"})')
).toMatchInlineSnapshot(`"<h3 hi=\\"there\\" />;"`)
).toMatchInlineSnapshot('"<h3 />;"')
})

it('should handle spread props', () => {
Expand All @@ -58,19 +58,19 @@ describe('babel-restore-jsx', () => {
it('should handle mixed props', () => {
expect(
jsx('React.createElement("h1", _extends({ hi: "there" }, props))')
).toMatchInlineSnapshot(`"<h1 hi=\\"there\\" {...props} />;"`)
).toMatchInlineSnapshot('"<h1 {...props} />;"')
expect(
jsx('React.createElement("h1", _extends({}, props, { hi: "there" }))')
).toMatchInlineSnapshot(`"<h1 {...props} hi=\\"there\\" />;"`)
).toMatchInlineSnapshot('"<h1 {...props} />;"')
expect(
jsx('React.createElement("h1", { ...props, hi: "there" })')
).toMatchInlineSnapshot(`"<h1 {...props} hi=\\"there\\" />;"`)
).toMatchInlineSnapshot('"<h1 />;"')
})

it('should handle props and ignore “null”/“undefined” children', () => {
expect(
jsx('React.createElement("h1", {hi: there}, null, undefined)')
).toMatchInlineSnapshot(`"<h1 hi={there} />;"`)
).toMatchInlineSnapshot('"<h1 />;"')
})

it('should ignore “null”/“undefined” props and handle children', () => {
Expand All @@ -93,7 +93,7 @@ describe('babel-restore-jsx', () => {
//we extensively tested props and children separately, so only sth. basic
expect(
jsx('React.createElement("h1", {hi: there}, "Header")')
).toMatchInlineSnapshot(`"<h1 hi={there}>Header</h1>;"`)
).toMatchInlineSnapshot('"<h1>Header</h1>;"')
})

it('should ignore intermingled “null”/“undefined” children', () => {
Expand All @@ -116,27 +116,17 @@ describe('babel-restore-jsx', () => {
)
})

it('should not handle contains __self prop', () => {
expect(jsx('React.createElement(Provider, { __self: this })'))
.toMatchInlineSnapshot(`
"React.createElement(Provider, {
__self: this
});"
`)
it('should remove __self prop', () => {
expect(
jsx('React.createElement(Provider, { __self: this })')
).toMatchInlineSnapshot('"<Provider />;"')
})

it('should not handle contains __source prop', () => {
it('should remove __source prop', () => {
expect(
jsx(
'React.createElement(Provider, { __source: { fileName: _jsxFileName, lineNumber: 133 }})'
`React.createElement(Provider, { __source: { fileName: 'jsxFileName', lineNumber: 133 }})`
)
).toMatchInlineSnapshot(`
"React.createElement(Provider, {
__source: {
fileName: _jsxFileName,
lineNumber: 133
}
});"
`)
).toMatchInlineSnapshot('"<Provider />;"')
})
})

0 comments on commit f6a55e1

Please sign in to comment.