},
+) => React.ReactElement) & { displayName?: string };
+
+if (process.env.NODE_ENV !== 'production') {
+ Segmented.displayName = 'Segmented';
+}
export default Segmented;
diff --git a/tests/__snapshots__/index.test.tsx.snap b/tests/__snapshots__/index.test.tsx.snap
index fb6277d..327991d 100644
--- a/tests/__snapshots__/index.test.tsx.snap
+++ b/tests/__snapshots__/index.test.tsx.snap
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`rc-segmented render empty options segmented 1`] = `
+
+`;
+
exports[`rc-segmented render empty segmented 1`] = `
{
expect(asFragment().firstChild).toMatchSnapshot();
});
+ it('render empty options segmented', () => {
+ const { asFragment } = render();
+ expect(asFragment().firstChild).toMatchSnapshot();
+ });
+
it('render segmented ok', () => {
const { container, asFragment } = render(
{
});
it('render segmented with controlled mode', () => {
- const offsetParentSpy = jest
- .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
- .mockImplementation(() => {
- return container;
- });
-
const Demo = () => {
const options = ['iOS', 'Android', 'Web3'];
@@ -257,6 +256,12 @@ describe('rc-segmented', () => {
};
const { container } = render();
+ const offsetParentSpy = jest
+ .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
+ .mockImplementation(() => {
+ return container;
+ });
+
fireEvent.click(container.querySelectorAll('.rc-segmented-item-input')[0]);
expect(container.querySelector('.value')?.textContent).toBe('iOS');
@@ -297,11 +302,6 @@ describe('rc-segmented', () => {
describe('render segmented with CSSMotion', () => {
it('basic', () => {
- const offsetParentSpy = jest
- .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
- .mockImplementation(() => {
- return container;
- });
const handleValueChange = jest.fn();
const { container, asFragment } = render(
{
onChange={(value) => handleValueChange(value)}
/>,
);
+
+ const offsetParentSpy = jest
+ .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
+ .mockImplementation(() => {
+ return container;
+ });
+
expect(asFragment().firstChild).toMatchSnapshot();
expectMatchChecked(container, [true, false, false]);
@@ -385,11 +392,6 @@ describe('rc-segmented', () => {
});
it('quick switch', () => {
- const offsetParentSpy = jest
- .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
- .mockImplementation(() => {
- return container;
- });
const { container } = render(
{
/>,
);
+ const offsetParentSpy = jest
+ .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
+ .mockImplementation(() => {
+ return container;
+ });
+
// >>> Click: Web3
fireEvent.click(
container.querySelectorAll('.rc-segmented-item-input')[2],
@@ -525,11 +533,6 @@ describe('rc-segmented', () => {
});
it('click can work as expected with rtl', () => {
- const offsetParentSpy = jest
- .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
- .mockImplementation(() => {
- return container;
- });
const handleValueChange = jest.fn();
const { container } = render(
{
/>,
);
+ const offsetParentSpy = jest
+ .spyOn(HTMLElement.prototype, 'offsetParent', 'get')
+ .mockImplementation(() => {
+ return container;
+ });
+
fireEvent.click(container.querySelectorAll('.rc-segmented-item-input')[1]);
expectMatchChecked(container, [false, true, false]);
expect(handleValueChange).toBeCalledWith('Android');
diff --git a/tsconfig.json b/tsconfig.json
index 850f783..4681e24 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,5 +19,5 @@
"rc-segmented": ["src/index.tsx"]
}
},
- "include": [".dumi/**/*", ".dumirc.ts", "src", "tests", "docs/examples"],
+ "include": [".dumirc.ts", "**/*"]
}