2022-11-14 15:59:22 +08:00
|
|
|
/**
|
|
|
|
|
* @vitest-environment jsdom
|
|
|
|
|
*/
|
2022-06-28 11:38:39 +08:00
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import { expect, it, describe } from 'vitest';
|
|
|
|
|
import { render } from '@testing-library/react';
|
2022-09-07 14:49:54 +08:00
|
|
|
import createPortal from '../src/create-portal';
|
2022-06-28 11:38:39 +08:00
|
|
|
|
|
|
|
|
describe('createPortal', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
const Portal = ({ children }) => {
|
|
|
|
|
return createPortal(children, div);
|
|
|
|
|
};
|
2022-09-07 14:49:54 +08:00
|
|
|
|
2022-06-28 11:38:39 +08:00
|
|
|
function App() {
|
2022-09-07 14:49:54 +08:00
|
|
|
return (<div>
|
2022-06-28 11:38:39 +08:00
|
|
|
<Portal>
|
|
|
|
|
<text>Hello Rax</text>
|
|
|
|
|
</Portal>
|
2022-09-07 14:49:54 +08:00
|
|
|
</div>);
|
2022-06-28 11:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
2022-06-28 14:59:37 +08:00
|
|
|
render(<App />);
|
2022-06-28 11:38:39 +08:00
|
|
|
expect(div.childNodes.length).toBe(1);
|
|
|
|
|
});
|
2022-06-28 14:40:55 +08:00
|
|
|
});
|