podman-desktop / extension-minikube

Apache License 2.0
3 stars 10 forks source link

fix: remove try catch from tests #225

Closed axel7083 closed 1 week ago

axel7083 commented 1 week ago

Removing all try { ... } catch from *.spec.ts file.

vitest let's us have a better alternative

before

try {
     // do something
} catch(err) {
    expect(err).to.be.a(Error);
}

after

await expect(async () => {
     // do something
}).rejects.toThrowError('the error')

This is very hard to add proper typecheck to an unknown, when we can have vitest do the job for us, and ensure we have a better error handling.

The expect error if Kubernetes reports error is removed because it was not testing anything, as no error is never raised, but since we only do expect in the catch block, the test was green.

I had to change the (extensionApi.process.exec as Mock) to vi.mocked(extensionApi.process.exec) because the test where not testing the right arguments

axel7083 commented 1 week ago

Try/catch is not the proper way anyway to use in unit tests

+1 to https://github.com/podman-desktop/podman-desktop/issues/9821