-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
267f2d0
commit c0700be
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
import { generate } from './generator'; | ||
import type { Template } from '@pdfme/common'; | ||
|
||
describe('Testing mock generate util', () => { | ||
test('should return a Promise', async () => { | ||
const result = generate({ template: {}, inputs: [] }); | ||
const result = generate({ | ||
template: { schemas: [] } as Template, | ||
inputs: [], | ||
}); | ||
expect(result).toBeInstanceOf(Promise); | ||
}); | ||
|
||
test('should resolve to a Uint8Array', async () => { | ||
const result = generate({ template: {}, inputs: [] }); | ||
const result = generate({ | ||
template: { schemas: [] } as Template, | ||
inputs: [], | ||
}); | ||
expect(result).toBeInstanceOf(Uint8Array); | ||
}); | ||
|
||
it('should throw an error when template is empty', async () => { | ||
const emptyTemplate = { schemas: [] } as Template; | ||
const validInputs = [{ field1: 'value1' }]; | ||
|
||
await expect( | ||
generate({ template: emptyTemplate, inputs: validInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
|
||
it('should throw an error when inputs are empty', async () => { | ||
const validTemplate = { schemas: [{ name: 'field1' }] } as Template; | ||
const emptyInputs: Record<string, string>[] = []; | ||
|
||
await expect( | ||
generate({ template: validTemplate, inputs: emptyInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
|
||
it('should throw an error when both template and inputs are empty', async () => { | ||
const emptyTemplate = { schemas: [] } as Template; | ||
const emptyInputs: Record<string, string>[] = []; | ||
|
||
await expect( | ||
generate({ template: emptyTemplate, inputs: emptyInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters