mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-25 13:47:39 +02:00
More test tidying
This commit is contained in:
parent
e7f6fd5e91
commit
274b545fe4
@ -122,11 +122,8 @@ describe('useSanitizeOperation', () => {
|
|||||||
const testFile = new File(['test'], 'test.pdf', { type: 'application/pdf' });
|
const testFile = new File(['test'], 'test.pdf', { type: 'application/pdf' });
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
try {
|
await expect(result.current.executeOperation(parameters, [testFile], mockGenerateSanitizedFileName))
|
||||||
await result.current.executeOperation(parameters, [testFile], mockGenerateSanitizedFileName);
|
.rejects.toThrow('Failed to sanitize all files: test.pdf');
|
||||||
} catch (error) {
|
|
||||||
// Expected to throw
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.isLoading).toBe(false);
|
expect(result.current.isLoading).toBe(false);
|
||||||
@ -147,18 +144,11 @@ describe('useSanitizeOperation', () => {
|
|||||||
removeFonts: false
|
removeFonts: false
|
||||||
};
|
};
|
||||||
|
|
||||||
let thrownError: Error | null = null;
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
try {
|
await expect(result.current.executeOperation(parameters, [], mockGenerateSanitizedFileName))
|
||||||
await result.current.executeOperation(parameters, [], mockGenerateSanitizedFileName);
|
.rejects.toThrow('No files selected');
|
||||||
} catch (error) {
|
|
||||||
thrownError = error as Error;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// The error should be thrown
|
|
||||||
expect(thrownError).toBeInstanceOf(Error);
|
|
||||||
expect(thrownError!.message).toBe('No files selected');
|
|
||||||
expect(mockFetch).not.toHaveBeenCalled();
|
expect(mockFetch).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -211,7 +201,7 @@ describe('useSanitizeOperation', () => {
|
|||||||
expect(result.current.downloadUrl).toBe(null);
|
expect(result.current.downloadUrl).toBe(null);
|
||||||
expect(result.current.errorMessage).toBe(null);
|
expect(result.current.errorMessage).toBe(null);
|
||||||
expect(result.current.status).toBe(null);
|
expect(result.current.status).toBe(null);
|
||||||
expect(globalThis.URL.revokeObjectURL).not.toHaveBeenCalled(); // No URL to revoke initially
|
expect(mockRevokeObjectURL).not.toHaveBeenCalled(); // No URL to revoke initially
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should clear error message', async () => {
|
test('should clear error message', async () => {
|
||||||
@ -237,11 +227,8 @@ describe('useSanitizeOperation', () => {
|
|||||||
|
|
||||||
// Trigger an API error
|
// Trigger an API error
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
try {
|
await expect(result.current.executeOperation(parameters, [testFile], mockGenerateSanitizedFileName))
|
||||||
await result.current.executeOperation(parameters, [testFile], mockGenerateSanitizedFileName);
|
.rejects.toThrow('Failed to sanitize all files: test.pdf');
|
||||||
} catch (error) {
|
|
||||||
// Expected to throw
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.errorMessage).toBe('Failed to sanitize all files: test.pdf');
|
expect(result.current.errorMessage).toBe('Failed to sanitize all files: test.pdf');
|
||||||
|
Loading…
Reference in New Issue
Block a user