test(theme-common): improve test coverage (#6902)

* test(theme-common): improve test coverage

* revert
This commit is contained in:
Joshua Chen 2022-03-12 13:17:21 +08:00 committed by GitHub
parent aa5a2d4c04
commit f6baaa6b75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1183 additions and 755 deletions

View file

@ -75,17 +75,17 @@ describe('truncate', () => {
it('truncates texts', () => {
expect(
truncate('aaa\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/),
).toEqual('aaa\n');
expect(
truncate('\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/),
).toEqual('\n');
).toBe('aaa\n');
expect(truncate('\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/)).toBe(
'\n',
);
});
it('leaves texts without markers', () => {
expect(truncate('aaa\nbbb\nccc', /<!-- truncate -->/)).toEqual(
expect(truncate('aaa\nbbb\nccc', /<!-- truncate -->/)).toBe(
'aaa\nbbb\nccc',
);
expect(truncate('', /<!-- truncate -->/)).toEqual('');
expect(truncate('', /<!-- truncate -->/)).toBe('');
});
});

View file

@ -341,7 +341,7 @@ describe('blog plugin', () => {
(v) => v.metadata.title === 'Happy 1st Birthday Slash! (translated)',
)!;
expect(localizedBlogPost.metadata.editUrl).toEqual(
expect(localizedBlogPost.metadata.editUrl).toBe(
`${BaseEditUrl}/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md`,
);
});
@ -478,7 +478,7 @@ describe('blog plugin', () => {
postsPerPage: 2,
});
expect(Object.keys(blogTags).length).toEqual(2);
expect(Object.keys(blogTags)).toHaveLength(2);
expect(blogTags).toMatchSnapshot();
});

View file

@ -15,7 +15,7 @@ describe('blog plugin options schema', () => {
it('normalizes options', () => {
const {value, error} = PluginOptionSchema.validate({});
expect(value).toEqual(DEFAULT_OPTIONS);
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('accepts correctly defined user options', () => {
@ -32,7 +32,7 @@ describe('blog plugin options schema', () => {
...userOptions,
feedOptions: {type: ['rss'], title: 'myTitle', copyright: ''},
});
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('accepts valid user options', async () => {
@ -49,7 +49,7 @@ describe('blog plugin options schema', () => {
};
const {value, error} = PluginOptionSchema.validate(userOptions);
expect(value).toEqual(userOptions);
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('throws Error in case of invalid options', () => {
@ -91,7 +91,7 @@ describe('blog plugin options schema', () => {
...DEFAULT_OPTIONS,
feedOptions: {type: null},
});
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('contains array with rss + atom for missing feed type', () => {
@ -117,14 +117,14 @@ describe('blog sidebar', () => {
const userOptions = {blogSidebarCount: 0};
const {value, error} = PluginOptionSchema.validate(userOptions);
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('accepts "ALL" sidebar count', () => {
const userOptions = {blogSidebarCount: 'ALL'};
const {value, error} = PluginOptionSchema.validate(userOptions);
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('rejects "abcdef" sidebar count', () => {
@ -139,7 +139,7 @@ describe('blog sidebar', () => {
const userOptions = {blogSidebarTitle: 'all posts'};
const {value, error} = PluginOptionSchema.validate(userOptions);
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
expect(error).toBe(undefined);
expect(error).toBeUndefined();
});
it('rejects 42 sidebar title', () => {