Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 6894401

Browse files
committed
test(inject-*): Add and passed inject test.
1 parent ff3a67b commit 6894401

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

test/inject-client-css.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { injectClientCSS } from '../src/_internal';
2+
3+
test('injectClientCSS correctly appends style element with expected content', () => {
4+
const hash = 'ABC12';
5+
const sheet = `.test-class_${hash} { color: red; }`;
6+
const context = 'Test Context';
7+
8+
injectClientCSS(hash, sheet, context);
9+
10+
const styleElement = document.getElementById(hash);
11+
expect(styleElement).not.toBeNull();
12+
expect(styleElement?.textContent).toContain(`.test-class_${hash} { color: red; }`);
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { injectClientGlobalCSS } from '../src/_internal';
2+
3+
test('injectClientGlobalCSS correctly appends global style element with expected content', () => {
4+
const scoped = 'global-scope';
5+
const sheet = '.global-class { color: blue; }';
6+
7+
injectClientGlobalCSS(sheet, scoped);
8+
9+
const styleElement = document.querySelector(`[data-scope="${scoped}"]`);
10+
expect(styleElement).not.toBeNull();
11+
expect(styleElement?.textContent).toContain('.global-class { color: blue; }');
12+
});

test/inject-server-css.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { getServerCSS } from '../src/_internal/utils/inject-server-css';
2+
3+
test('returns null when isDevServer is false', () => {
4+
// Assuming isDevServer is set to false in this test environment
5+
// running the case where isDevServer is true in e2e testing.
6+
const injectedCSS = getServerCSS();
7+
expect(injectedCSS).toBeNull();
8+
});

0 commit comments

Comments
 (0)