Skip to content

Commit

Permalink
[not verified] Add newsletter categories mock function for testing
Browse files Browse the repository at this point in the history
In the subscriptions module, a mock function was added in the test/edit.js file. This was done to simulate the behavior of the actual 'useNewsletterCategories' function in the unit tests. This will facilitate the testing process by controlling its response and help in improving the code coverage.
  • Loading branch information
TimBroddin committed Aug 30, 2023
1 parent 4335c2d commit fc89c1f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ jest.mock( '@wordpress/element', () => ( {

jest.mock( '@wordpress/notices', () => {}, { virtual: true } );

jest.mock( '../hooks/use-newsletter-categories', () => ( {
useNewsletterCategories: () => {
return {
data: [],
enabled: false,
error: false,
loading: false,
};
},
} ) );

describe( 'SubscriptionEdit', () => {
test( 'adds correct classes to container', async () => {
const { container } = render( <SubscriptionEdit { ...defaultProps } /> );

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect( container.querySelector( `.${ defaultProps.className }` ) ).toBeInTheDocument();
} );
Expand Down

0 comments on commit fc89c1f

Please sign in to comment.