ant-design/components/_util/__tests__/useMounted.test.js

21 lines
463 B
JavaScript
Raw Normal View History

2021-12-28 17:21:00 +08:00
import { mount } from 'enzyme';
import React from 'react';
import useMounted from '../hooks/useMounted';
2021-12-28 17:21:00 +08:00
describe('useMounted', () => {
2021-12-28 17:21:00 +08:00
it('should work properly', () => {
let isMounted = null;
2021-12-28 17:21:00 +08:00
const AutoUnmounted = () => {
isMounted = useMounted();
2021-12-28 17:21:00 +08:00
return <div>Mounted</div>;
};
const wrapper = mount(<AutoUnmounted />);
expect(isMounted()).toBeTruthy();
2021-12-28 17:21:00 +08:00
wrapper.unmount();
expect(isMounted()).toBeFalsy();
2021-12-28 17:21:00 +08:00
});
});