-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ui/unit tests to BarCodeScanScreen NotificationsScreen #367
Comments
Git action CI test is failing for quite some time
https://github.com/NMF-earth/nmf-app/actions/workflows/test.yml |
Indeed, the CI is failing for quite some time and I haven't figured why. The tests/snapshots passed/total numbers are identical |
The CI is failing even when all tests are succeeding because 2 tests are logging errors on the console.
I was able to disable these tests in my forked repo which lead the CI to succeed The tests are failing with the same error BarCodeScanScreen
NotificationsScreen
These tests don't do much, it just matches snapshot of the screens. |
I tried to fix these tests but did not succeed. I tried wrapping the create() function in act but it didn't fail One thing in common to both these screens is that they use async method calls in useEffect to check permissions for sending notification or reading barcode useEffect(() => {
(async () => {
const { status } = await BarCodeScanner.requestPermissionsAsync();
setHasPermission(status === "granted");
})();
}, []); |
These tests are not testing anything significant, the Snapshot it validates is when there is no permission for Camera and Notification, if it helps to get the CI fixed, you might decide to disable these tests for now and enable them again with better coverage |
I managed to fix the issue from useEffect with |
Summarizing everything I tried to fix the test to avoid repeated efforts Move create function call in the test within act()it("BarCodeScanScreen renders correctly", async () => {
let tree= null;
act(() => {
tree = create(<BarCodeScanScreen />);
});
expect(tree.toJSON()).toMatchSnapshot();
}); This didn't fix the issue, however same error was reported on another line in the code Move to use render and waitFor function call in the test to wait for the useEffect to finishAdded dependency on it("BarCodeScanScreen renders correctly", async () => {
const tree = render(<BarCodeScanScreen />);
waitFor(tree.toJSON()).toMatchSnapshot();
});
|
Describe the bug
Tests are failing on main branch, see 366 and https://github.com/NMF-earth/nmf-app/actions/runs/4446824624
Find it why this was not catch on CI and fix Github Actions
The text was updated successfully, but these errors were encountered: