1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/thoughtworks-taro-testing-library

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
functional-component.test.tsx 2 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
z Отправлено 5 лет назад 3718ee8
import Taro, {useEffect, useState} from '@tarojs/taro';
import {Text} from "@tarojs/components";
import {StandardProps} from "@tarojs/components/types/common";
import { act, render, renderToString } from '../index';
interface CounterProps extends StandardProps {
initial?: number;
}
const Counter = (props: CounterProps) => {
const [count, setCount] = useState(props.initial || 1)
return (
<Text
onClick={() => {setCount(count+1)}}
className="number custom-class"
>{count}</Text>
);
};
describe('functional component test', () => {
it('should render component', () => {
const { container } = render(<Counter />);
const $number = container.querySelector('.number') as HTMLSpanElement;
expect($number.innerHTML).toEqual('1');
});
it('should render component with props', () => {
const initial = 10
const { container } = render(<Counter initial={initial} />);
const $number = container.querySelector('.number') as HTMLSpanElement;
expect($number.innerHTML).toEqual(`${initial}`);
});
it('should render component with props', () => {
const initial = 10
const { container } = render(<Counter initial={initial} />);
const $number = container.querySelector('.number') as HTMLSpanElement;
expect($number.innerHTML).toEqual(`${initial}`);
});
it('should rerender when trigger setState hooks', () => {
const { container } = render(<Counter />);
const $number = container.querySelector('.number') as HTMLSpanElement;
act(() => {
$number.click()
})
expect($number.innerHTML).toEqual(`2`);
});
it('should rerender when excute rerender methods', () => {
const { container, rerender } = render(<Counter />);
expect(container.querySelector('.number').innerHTML).toEqual("1");
rerender(<Counter initial={2} />)
expect(container.querySelector('.number').innerHTML).toEqual("2");
});
it('should support snapshot', () => {
const component = renderToString(<div>component without state</div>);
expect(component).toMatchSnapshot();
})
});

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/thoughtworks-taro-testing-library.git
git@gitlife.ru:oschina-mirror/thoughtworks-taro-testing-library.git
oschina-mirror
thoughtworks-taro-testing-library
thoughtworks-taro-testing-library
v1.1.0