-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// test/customElements/renderCustomElements.test.ts | ||
import { describe, test, expect } from 'vitest' | ||
import { setup, createPage } from '@nuxt/test-utils' | ||
import { fileURLToPath } from 'url' | ||
|
||
describe('renderCustomElements', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('../../playground', import.meta.url)), | ||
configFile: 'nuxt.config4test', | ||
port: 3001, | ||
}) | ||
|
||
const { $drupalCe } = useNuxtApp() | ||
const { renderCustomElements } = $drupalCe | ||
|
||
// ... rest of test cases remain the same ... | ||
test('handles null input', () => { | ||
const result = renderCustomElements(null) | ||
expect(result).toBe(null) | ||
}) | ||
|
||
test('handles undefined input', () => { | ||
const result = renderCustomElements(undefined) | ||
expect(result).toBe(null) | ||
}) | ||
|
||
test('handles empty object input', () => { | ||
const result = renderCustomElements({}) | ||
expect(result).toBe(null) | ||
}) | ||
|
||
test('handles plain string input', () => { | ||
const result = renderCustomElements('Hello World') | ||
expect(result).toMatchObject({ | ||
template: expect.stringContaining('v-html'), | ||
data: expect.any(Function) | ||
}) | ||
expect(result.data().content).toBe('Hello World') | ||
}) | ||
|
||
test('handles HTML string input', () => { | ||
const htmlString = '<p>Hello <strong>World</strong></p>' | ||
const result = renderCustomElements(htmlString) | ||
expect(result).toMatchObject({ | ||
template: expect.stringContaining('v-html'), | ||
data: expect.any(Function) | ||
}) | ||
expect(result.data().content).toBe(htmlString) | ||
}) | ||
|
||
test('handles single custom element object', () => { | ||
const customElement = { | ||
element: 'test-component', | ||
props: { foo: 'bar' } | ||
} | ||
const result = renderCustomElements(customElement) | ||
expect(result).toBeTruthy() | ||
expect(result).toHaveProperty('type') | ||
expect(result).toHaveProperty('props') | ||
expect(result.props).toMatchObject({ | ||
foo: 'bar' | ||
}) | ||
}) | ||
|
||
test('handles array of custom elements', () => { | ||
const customElements = [ | ||
{ | ||
element: 'test-component', | ||
props: { foo: 'bar' } | ||
}, | ||
'Plain text element', | ||
{ | ||
element: 'another-component', | ||
props: { baz: 'qux' } | ||
} | ||
] | ||
const result = renderCustomElements(customElements) | ||
expect(Array.isArray(result)).toBe(true) | ||
expect(result).toHaveLength(3) | ||
|
||
expect(result[0]).toHaveProperty('type') | ||
expect(result[0]).toHaveProperty('props') | ||
expect(result[0].props).toMatchObject({ | ||
foo: 'bar' | ||
}) | ||
|
||
expect(result[1]).toMatchObject({ | ||
template: expect.stringContaining('v-html'), | ||
data: expect.any(Function) | ||
}) | ||
expect(result[1].data().content).toBe('Plain text element') | ||
|
||
expect(result[2]).toHaveProperty('type') | ||
expect(result[2]).toHaveProperty('props') | ||
expect(result[2].props).toMatchObject({ | ||
baz: 'qux' | ||
}) | ||
}) | ||
|
||
test('handles array with only string elements', () => { | ||
const elements = ['Text 1', '<p>HTML text</p>'] | ||
const result = renderCustomElements(elements) | ||
expect(Array.isArray(result)).toBe(true) | ||
expect(result).toHaveLength(2) | ||
|
||
result.forEach((component, index) => { | ||
expect(component).toMatchObject({ | ||
template: expect.stringContaining('v-html'), | ||
data: expect.any(Function) | ||
}) | ||
expect(component.data().content).toBe(elements[index]) | ||
}) | ||
}) | ||
}) |