File size: 2,293 Bytes
1e92f2d |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import { resolveImages, resolveOpenGraph } from './resolve-opengraph'
describe('resolveImages', () => {
const image1 = 'https://www.example.com/image1.jpg'
const image2 = 'https://www.example.com/image2.jpg'
it(`should resolve images`, () => {
const images = [image1, { url: image2, alt: 'Image2' }]
expect(resolveImages(images, null, false)).toEqual([
{ url: new URL(image1) },
{ url: new URL(image2), alt: 'Image2' },
])
})
it('should not mutate passed images', () => {
const images = [image1, { url: image2, alt: 'Image2' }]
resolveImages(images, null, false)
expect(images).toEqual([image1, { url: image2, alt: 'Image2' }])
})
it('should filter out invalid images', () => {
const images = [
image1,
{ url: image2, alt: 'Image2' },
{ alt: 'Image3' },
undefined,
]
// @ts-expect-error - intentionally passing invalid images
expect(resolveImages(images, null)).toEqual([
{ url: new URL(image1) },
{ url: new URL(image2), alt: 'Image2' },
])
})
})
describe('resolveOpenGraph', () => {
it('should return null if the value is an empty string', async () => {
const pathname = Promise.resolve('')
expect(
await resolveOpenGraph(
// pass authors as empty string
{ type: 'article', authors: '' },
null,
pathname,
{
trailingSlash: false,
isStaticMetadataRouteFile: false,
},
''
)
).toEqual({
// if an empty string '' is passed, it'll throw: "n.map is not a function"
// x-ref: https://github.com/vercel/next.js/pull/68262
authors: null,
images: undefined,
title: { absolute: '', template: null },
type: 'article',
url: null,
})
})
it('should return null if the value is null', async () => {
const pathname = Promise.resolve('')
expect(
await resolveOpenGraph(
{ type: 'article', authors: null },
null,
pathname,
{
trailingSlash: false,
isStaticMetadataRouteFile: false,
},
''
)
).toEqual({
authors: null,
images: undefined,
title: { absolute: '', template: null },
type: 'article',
url: null,
})
})
})
|