-
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.
- Loading branch information
Showing
1 changed file
with
41 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,41 @@ | ||
import React, { FC } from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import { useDataCommonContext, Status as DCStatus, DataCommonProvider } from './DataCommonContext'; | ||
|
||
const TestChild: FC = () => { | ||
const { status } = useDataCommonContext(); | ||
|
||
if (status === DCStatus.LOADING) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div data-testid="status">{status}</div> | ||
); | ||
}; | ||
|
||
type Props = { | ||
dc: string; | ||
children?: React.ReactNode; | ||
}; | ||
|
||
const TestParent: FC<Props> = ({ dc, children } : Props) => ( | ||
<DataCommonProvider DataCommon={dc}> | ||
{children ?? <TestChild />} | ||
</DataCommonProvider> | ||
); | ||
|
||
describe("DataCommonContext > useDataCommonContext Tests", () => { | ||
it("should throw an exception when used outside of a DataCommonProvider", () => { | ||
jest.spyOn(console, "error").mockImplementation(() => {}); | ||
expect(() => render(<TestChild />)).toThrow("useDataCommonContext cannot be used outside of the DataCommonProvider component"); | ||
jest.spyOn(console, "error").mockRestore(); | ||
}); | ||
}); | ||
|
||
describe("DataCommonContext > DataCommonProvider Tests", () => { | ||
it("should render without crashing", () => { | ||
render(<TestParent dc="XYZ" />); | ||
}); | ||
}); |