-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathimages.spec.ts
38 lines (35 loc) · 1.28 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
/**
* @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: /tawny frogmouth/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.request('/broken-image').then((response) => {
expect(response.status).to.eq(500)
expect(response.body).to.include(
'hostname "broken-domain" is not configured under images in your `next.config.js`',
)
})
})
})