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
|
import { describe, expect, test } from 'vitest';
import { createMetadata } from './metadata';
describe('createMetadata', () => {
test('builds metadata with default open graph, twitter, and alternates fields', () => {
const metadata = createMetadata({
title: 'My Post',
description: 'Post description',
});
expect(metadata.openGraph).toMatchObject({
title: 'My Post',
description: 'Post description',
url: 'https://blog.techwithanirudh.com',
images: '/banner.png',
siteName: 'Blog',
});
expect(metadata.twitter).toMatchObject({
card: 'summary_large_image',
creator: '@AnirudhWith',
title: 'My Post',
description: 'Post description',
images: '/banner.png',
});
expect(metadata.alternates).toMatchObject({
canonical: '/',
types: {
'application/rss+xml': '/api/rss.xml',
},
});
});
test('allows nested metadata fields to override defaults and top-level fallbacks', () => {
const metadata = createMetadata({
title: 'Top Level Title',
openGraph: {
title: 'OG Title',
url: 'https://example.com/posts/1',
},
twitter: {
title: 'Twitter Title',
card: 'summary',
},
alternates: {
canonical: '/posts/1',
},
});
expect(metadata.openGraph?.title).toBe('OG Title');
expect(metadata.openGraph?.url).toBe('https://example.com/posts/1');
expect(metadata.twitter?.title).toBe('Twitter Title');
expect(metadata.twitter?.card).toBe('summary');
expect(metadata.alternates?.canonical).toBe('/posts/1');
});
});
|