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