Skip to content

Commit

Permalink
add extra unit test covering createSitemapItems returning []
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Apr 30, 2024
1 parent c624788 commit 60eef87
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {createElement} from 'react';
import {fromPartial} from '@total-typescript/shoehorn';
import createSitemap from '../createSitemap';
import type {PluginOptions} from '../options';
Expand Down Expand Up @@ -115,6 +115,22 @@ describe('createSitemap', () => {
expect(sitemap).not.toContain('/tags');
});

it('returns null when createSitemapItems returns no items', async () => {
const sitemap = await createSitemap({
siteConfig,
routes: routes(['/', '/docs/myDoc/', '/blog/post']),
head: {},
options: {
...options,
createSitemapItems: async () => {
return [];
},
},
});

expect(sitemap).toBeNull();
});

it('keep trailing slash unchanged', async () => {
const sitemap = await createSitemap({
siteConfig,
Expand Down Expand Up @@ -171,7 +187,7 @@ describe('createSitemap', () => {
meta: {
// @ts-expect-error: bad lib def
toComponent: () => [
React.createElement('meta', {
createElement('meta', {
name: 'robots',
content: 'NoFolloW, NoiNDeX',
}),
Expand All @@ -195,15 +211,15 @@ describe('createSitemap', () => {
meta: {
// @ts-expect-error: bad lib def
toComponent: () => [
React.createElement('meta', {name: 'robots', content: 'noindex'}),
createElement('meta', {name: 'robots', content: 'noindex'}),
],
},
},
'/noindex': {
meta: {
// @ts-expect-error: bad lib def
toComponent: () => [
React.createElement('meta', {name: 'robots', content: 'noindex'}),
createElement('meta', {name: 'robots', content: 'noindex'}),
],
},
},
Expand Down

0 comments on commit 60eef87

Please sign in to comment.