test: improve unit test

This commit is contained in:
pengzhanbo 2025-12-05 17:06:41 +08:00
parent 5f82bdeb67
commit 29b5197c47
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest'
import { cleanMarkdownEnv, type CleanMarkdownEnv } from '../src/node/utils/cleanMarkdownEnv.js'
describe('cleanMarkdownEnv', () => {
const env: CleanMarkdownEnv = {
base: 'base',
filePath: 'filePath',
filePathRelative: 'filePathRelative',
references: 'references',
abbreviations: 'abbreviations',
annotations: 'annotations',
// @ts-expect-error should be ignored
foo: 'foo',
bar: 'bar',
}
it('should clean markdown env', () => {
const result = cleanMarkdownEnv(env)
expect(result).toEqual({
base: 'base',
filePath: 'filePath',
filePathRelative: 'filePathRelative',
references: 'references',
abbreviations: 'abbreviations',
annotations: 'annotations',
})
})
it('should clean markdown env with excludes', () => {
const result = cleanMarkdownEnv(env, ['references', 'abbreviations'])
expect(result).toEqual({
base: 'base',
filePath: 'filePath',
filePathRelative: 'filePathRelative',
annotations: 'annotations',
})
})
})

View File

@ -45,6 +45,10 @@ describe('stringifyAttrs', () => {
expect(stringifyAttrs({ id: '{ "foo": "bar", baz: 1 }', class: '["a", "b"]' })).toBe(' :id="{ \'foo\': \'bar\', baz: 1 }" :class="[\'a\', \'b\']"')
})
it('should handle like json string values with force stringify', () => {
expect(stringifyAttrs({ id: '{ "foo": "bar", baz: 1 }', class: '["a", "b"]' }, false, ['class'])).toBe(' :id="{ \'foo\': \'bar\', baz: 1 }" class="[\'a\', \'b\']"')
})
it('should handle kebabCase keys', () => {
expect(stringifyAttrs({ 'data-foo': 'bar', 'data-baz': 1, 'fooBaz': 'bar' })).toBe(' data-foo="bar" :data-baz="1" foo-baz="bar"')
})