UNPKG

@cainiaofe/cn-ui-m

Version:
25 lines (24 loc) 1.14 kB
import React, { useContext } from 'react'; import { render, act } from '@testing-library/react'; import { CardItemsContext, CardItemsStateCtx } from '../card-items'; describe('CardItemsContext 组件检查', function () { var contextValue; var TestComponent = function () { var context = useContext(CardItemsStateCtx); contextValue = context; // 更新外部的 contextValue return (React.createElement("button", { onClick: function () { return context.setSelectedKeys(new Set([1])); } }, "\u66F4\u65B0 selectedKeys")); }; test('设置 selectedKeys 后 selectedDataSource 会同步更新', function () { var getByText = render(React.createElement(CardItemsContext, { tableProps: { dataSource: [ { id: 1, name: 'test' }, { id: 2, name: 'test2' }, ], } }, React.createElement(TestComponent, null))).getByText; act(function () { getByText('更新 selectedKeys').click(); }); expect(contextValue.selectedDataSource).toEqual([{ id: 1, name: 'test' }]); }); });