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

OSCHINA-MIRROR/thoughtworks-taro-testing-library

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
functional-component-effect.test.tsx 1.3 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
jiachen Отправлено 5 лет назад 4340154
import Taro, {useEffect, useState} from '@tarojs/taro';
import {Text, View} from "@tarojs/components";
import { render } from '../index';
import {StandardProps} from "@tarojs/components/types/common";
interface CounterProps extends StandardProps {
initial?: number;
}
const Counter = (props: CounterProps) => {
const {initial} = props
const [count, setCount] = useState(0)
useEffect(() => {
setCount(initial || 1)
}, [initial])
return (
<Text
onClick={() => {setCount(count+1)}}
className="number custom-class"
>{count}</Text>
);
};
const NestTest = () => {
const [count, setCount] = useState(10)
return (
<View>
<Counter initial={count}>{count}</Counter>
<View className="button" onClick={() => {setCount(20)}}>CLICK</View>
</View>
);
};
describe('useEffect test', () => {
it('should excute useEffect method', () => {
const { container } = render(<Counter />);
const number = container.querySelector('.number') as HTMLSpanElement;
expect(number.innerHTML).toEqual('1');
});
it('should excute useEffect method', () => {
const { container } = render(<NestTest />);
const number = container.querySelector('.number') as HTMLSpanElement;
expect(number.innerHTML).toEqual('10');
});
});

Комментарий ( 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