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

21 lines
477 B
JavaScript
Raw Normal View History

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