81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
/*
|
|
* Copyright (c) 2024 Huawei Technologies Co.,Ltd.
|
|
*
|
|
* openInula is licensed under Mulan PSL v2.
|
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
* You may obtain a copy of Mulan PSL v2 at:
|
|
*
|
|
* http://license.coscl.org.cn/MulanPSL2
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
* See the Mulan PSL v2 for more details.
|
|
*/
|
|
|
|
import { describe, expect, vi } from 'vitest';
|
|
import { domTest as it } from './utils';
|
|
import { render, View } from '../src';
|
|
|
|
describe('components', () => {
|
|
describe('ref', () => {
|
|
it('should support ref', ({ container }) => {
|
|
let ref: HTMLElement;
|
|
|
|
function App() {
|
|
let count = 0;
|
|
let _ref: HTMLElement;
|
|
|
|
didMount: {
|
|
ref = _ref;
|
|
}
|
|
|
|
return <div ref={_ref}>test</div>;
|
|
}
|
|
|
|
render(App, container);
|
|
|
|
expect(ref).toBeInstanceOf(HTMLElement);
|
|
});
|
|
|
|
it('should support ref with function', ({ container }) => {
|
|
const fn = vi.fn();
|
|
|
|
function App() {
|
|
const ref = (el: HTMLElement) => {
|
|
fn();
|
|
expect(el).toBeInstanceOf(HTMLElement);
|
|
};
|
|
|
|
return <div ref={ref}>test</div>;
|
|
}
|
|
|
|
render(App, container);
|
|
expect(fn).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('env', () => {
|
|
it('should support env', ({ container }) => {
|
|
function App() {
|
|
return (
|
|
<env theme="dark">
|
|
<Child name="child" />
|
|
</env>
|
|
);
|
|
}
|
|
|
|
function Child({ name }, { theme }) {
|
|
return (
|
|
<div>
|
|
name is {name}, theme is {theme}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
render(App, container);
|
|
expect(container.innerHTML).toBe('<div>name is child, theme is dark</div>');
|
|
});
|
|
});
|
|
});
|