-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test to ensure components are disposed (closes #17)
- Loading branch information
1 parent
26e3b4c
commit 1bfbe9e
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |