Skip to content

Commit dbd8558

Browse files
committed
test: fixed broken image test as it's different when deployed
1 parent 3d516e4 commit dbd8558

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cypress/integration/default/images.spec.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('next/images', () => {
1919

2020
it('should show image allow-listed with remotePatterns', () => {
2121
cy.visit('/image')
22-
cy.findByRole('img', { name: /tawny frogmouth/i })
22+
cy.findByRole('img', { name: /shiba inu dog looks through a window/i })
2323
.should('be.visible')
2424
.and(($img) => {
2525
// "naturalWidth" and "naturalHeight" are set when the image loads
@@ -28,11 +28,18 @@ describe('next/images', () => {
2828
})
2929

3030
it('should show throw if an image is not on the domains or remotePatterns allowlist', () => {
31-
cy.request({ url: '/broken-image', failOnStatusCode: false }).then((response) => {
32-
expect(response.status).to.be.eq(500)
33-
expect(response.body).to.include(
34-
`Invalid src prop (https://broken-domain/netlify/next-runtime/main/next-on-netlify.png)`,
35-
)
31+
cy.visit('/broken-image')
32+
33+
// The image renders broken on the site
34+
cy.findByRole('img', { name: /picture of the author/i }).then(($img) => {
35+
// eslint-disable-next-line promise/no-nesting
36+
cy.request({ url: $img[0].src, failOnStatusCode: false }).then((response) => {
37+
// Navigating to the image itself give a forbidden error with a message explaining why.
38+
expect(response.status).to.eq(403)
39+
expect(response.body).to.include(
40+
'URL not on allowlist: https://broken-domain/netlify/next-runtime/main/next-on-netlify.png',
41+
)
42+
})
3643
})
3744
})
3845
})

0 commit comments

Comments
 (0)