Skip to content

Commit

Permalink
correct typo
Browse files Browse the repository at this point in the history
  • Loading branch information
kb019 committed Nov 22, 2024
1 parent ada9c49 commit b2d8ad1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import React, { Component } from 'react';
import { render, screen, waitFor} from '@testing-library/react';
import { openmrsComponentDecorator } from './openmrsComponentDecorator';
import { ComponentContext } from './ComponentContext';

Expand Down Expand Up @@ -35,6 +35,22 @@ describe('openmrs-component-decorator', () => {
const DecoratedComp = openmrsComponentDecorator(opts)(CompWithConfig);
render(<DecoratedComp />);
});

it("rendering a unsafe component is strict mode should log error in console",()=>{
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
const UnsafeDecoratedCompnent = openmrsComponentDecorator(opts)(UnsafeComponent);
render(<UnsafeDecoratedCompnent/>);
expect(consoleError.mock.calls[0][0]).toContain('Warning: Using UNSAFE_componentWillMount');
consoleError.mockRestore();
})

it("rendering an unsafe component without strict mode should not log an error in console",()=>{
const spy = jest.spyOn(console, "error");
const unsafeComponentOptions=Object.assign(opts,{strictMode:false})
const UnsafeDecoratedCompnent = openmrsComponentDecorator(unsafeComponentOptions)(UnsafeComponent);
render(<UnsafeDecoratedCompnent/>);
expect(spy).not.toHaveBeenCalled();
})
});

function CompThatWorks() {
Expand All @@ -49,3 +65,15 @@ function CompWithConfig() {
const { moduleName } = React.useContext(ComponentContext);
return <div>{moduleName}</div>;
}


class UnsafeComponent extends Component<any,any> {

UNSAFE_componentWillMount() {

}

render() {
return <h1>This is Unsafe Component</h1>;
}
};

Check failure on line 79 in packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx

View workflow job for this annotation

GitHub Actions / build

Unnecessary semicolon
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export function openmrsComponentDecorator<T>(userOpts: ComponentDecoratorOptions
</SWRConfig>
</Suspense>
);

if (opts.strictMode || !React.StrictMode) {
if (!opts.strictMode || !React.StrictMode) {
return content;
} else {
return <React.StrictMode>{content}</React.StrictMode>;
Expand Down

0 comments on commit b2d8ad1

Please sign in to comment.