-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathimages.spec.ts
45 lines (41 loc) · 1.66 KB
/
images.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @see {@link https://nextjs.org/docs/api-reference/next/image#required-props}
*/
describe('next/images', () => {
it('should show static image from /public', () => {
cy.visit('/')
cy.findByRole('img')
.should('be.visible')
.and(($img) => {
// "naturalWidth" and "naturalHeight" are set when the image loads
expect($img[0].naturalWidth, 'image has natural width').to.be.greaterThan(0)
})
})
it('should show image using next/image', () => {
cy.visit('/image')
cy.findByRole('img', { name: /shiba inu dog looks through a window/i })
})
it('should show image allow-listed with remotePatterns', () => {
cy.visit('/image')
cy.findByRole('img', { name: /shiba inu dog looks through a window/i })
.should('be.visible')
.and(($img) => {
// "naturalWidth" and "naturalHeight" are set when the image loads
expect($img[0].naturalWidth, 'image has natural width').to.be.greaterThan(0)
})
})
it('should show throw if an image is not on the domains or remotePatterns allowlist', () => {
cy.visit('/broken-image')
// The image renders broken on the site
cy.findByRole('img', { name: /picture of the author/i }).then(($img) => {
// eslint-disable-next-line promise/no-nesting
cy.request({ url: $img[0].src, failOnStatusCode: false }).then((response) => {
// Navigating to the image itself give a forbidden error with a message explaining why.
expect(response.status).to.eq(403)
expect(response.body).to.include(
'URL not on allowlist: https://netlify-plugin-nextjs-demo.netlify.app/next-on-netlify.png',
)
})
})
})
})