mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Error when getImage() is passed an undefined src (#9423)
This commit is contained in:
parent
836ab6214e
commit
bda1d294f2
4 changed files with 14 additions and 4 deletions
5
.changeset/brown-apricots-kick.md
Normal file
5
.changeset/brown-apricots-kick.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Error when getImage is passed an undefined src
|
|
@ -79,6 +79,12 @@ export async function getImage(
|
|||
message: AstroErrorData.ExpectedImageOptions.message(JSON.stringify(options)),
|
||||
});
|
||||
}
|
||||
if(typeof options.src === 'undefined') {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.ExpectedImage,
|
||||
message: AstroErrorData.ExpectedImage.message(options.src, 'undefined', JSON.stringify(options))
|
||||
});
|
||||
}
|
||||
|
||||
const service = await getConfiguredImageService();
|
||||
|
||||
|
|
|
@ -640,14 +640,13 @@ describe('astro:image', () => {
|
|||
expect(logs[0].message).to.contain('Expected getImage() parameter');
|
||||
});
|
||||
|
||||
// TODO: For some reason, this error crashes the dev server?
|
||||
it.skip('properly error when src is undefined', async () => {
|
||||
it('properly error when src is undefined', async () => {
|
||||
logs.length = 0;
|
||||
let res = await fixture.fetch('/get-image-undefined');
|
||||
await res.text();
|
||||
|
||||
expect(logs).to.have.a.lengthOf(1);
|
||||
expect(logs[0].message).to.contain('Expected src to be an image.');
|
||||
expect(logs[0].message).to.contain('Expected `src` property');
|
||||
});
|
||||
|
||||
it('properly error image in Markdown frontmatter is not found', async () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
import { getImage } from "astro:assets";
|
||||
|
||||
const myImage = getImage({src: undefined});
|
||||
const myImage = await getImage({src: undefined});
|
||||
---
|
||||
|
|
Loading…
Reference in a new issue