Skip to content

Commit

Permalink
add test to ensure components are disposed (closes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanBerliner committed Aug 12, 2021
1 parent 26e3b4c commit 1bfbe9e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/hooks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, {useRef} from 'react';
import {useBootstrap} from '../src/lib/hooks';
import {render} from '@testing-library/react';

describe('use bootstrap hook', () => {
test('disposes component on unmount', () => {
const dispose = jest.fn();

/**
* Fake bootstrap component
*/
class Component {
/**
* Mock bootstraps dispose, which calls our mock we can spy on
*/
dispose() {
dispose();
}

/**
* Mock bootstraps getInstance
*/
static getInstance() {
return null;
}
};

const events = new Map([]);
const config = {};

/**
* React component that uses the useBootstrap hook
*/
function TestComponent() {
const ref = useRef();
useBootstrap(Component, config, undefined, ref, events);
return <span ref={ref}></span>;
}

const {unmount} = render(<TestComponent />);
unmount();

expect(dispose).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 1bfbe9e

Please sign in to comment.