2021-12-28 17:21:00 +08:00
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import React from 'react';
|
2021-12-29 14:42:00 +08:00
|
|
|
import useMounted from '../hooks/useMounted';
|
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 14:42:00 +08:00
|
|
|
let isMounted = null;
|
2021-12-28 17:21:00 +08:00
|
|
|
|
|
|
|
const AutoUnmounted = () => {
|
2021-12-29 14:42:00 +08:00
|
|
|
isMounted = useMounted();
|
2021-12-28 17:21:00 +08:00
|
|
|
|
|
|
|
return <div>Mounted</div>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(<AutoUnmounted />);
|
2021-12-29 14:42:00 +08:00
|
|
|
expect(isMounted()).toBeTruthy();
|
2021-12-28 17:21:00 +08:00
|
|
|
wrapper.unmount();
|
2021-12-29 14:42:00 +08:00
|
|
|
expect(isMounted()).toBeFalsy();
|
2021-12-28 17:21:00 +08:00
|
|
|
});
|
|
|
|
});
|