summaryrefslogtreecommitdiff
path: root/packages/astro/test/jsx.test.js
blob: 64c7a7609fcd61b41fe298b578e93383c17a1f0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('jsx-runtime', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/jsx/',
		});
		await fixture.build();
	});

	it('Can load simple JSX components', async () => {
		const html = await fixture.readFile('/component/index.html');
		const $ = cheerio.load(html);

		expect($('#basic').text()).to.equal('Basic');
		expect($('#named').text()).to.equal('Named');
	});

	it('Can load Preact component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#has-preact #preact').length).to.equal(0);
		expect($('#preact').text()).to.include('Preact');
	});

	it('Can load React component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#has-react #react').length).to.equal(0);
		expect($('#react').text()).to.include('React');
	});

	it('Can load Solid component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#has-solid #solid').length).to.equal(0);
		expect($('#solid').text()).to.include('Solid');
	});

	it('Can load Svelte component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#has-svelte #svelte').length).to.equal(0);
		expect($('#svelte').text()).to.include('Svelte');
	});

	it('Can load Vue component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#has-vue #vue').length).to.equal(0);
		expect($('#vue').text()).to.include('Vue');
	});

	it('Can load MDX component inside Astro', async () => {
		const html = await fixture.readFile('/frameworks/index.html');
		const $ = cheerio.load(html);

		expect($('#mdx-wrapper #hello-world')).to.have.a.lengthOf(1, 'md content rendered');
		expect($('#mdx-wrapper #react')).to.have.a.lengthOf(1, 'React component rendered')
	});
});