refactor tests

This commit is contained in:
Philipp Kühn 2020-10-31 23:56:31 +01:00
parent cb647de043
commit d810054492
6 changed files with 17 additions and 28 deletions

View File

@ -13,10 +13,8 @@ export { default as nodeInputRule } from './src/inputRules/nodeInputRule'
export { default as markInputRule } from './src/inputRules/markInputRule'
export { default as markPasteRule } from './src/pasteRules/markPasteRule'
export { default as capitalize } from './src/utils/capitalize'
export { default as getSchema } from './src/utils/getSchema'
export { default as generateHTML } from './src/utils/generateHTML'
export { default as getHTMLFromFragment } from './src/utils/getHTMLFromFragment'
export { default as getMarkAttrs } from './src/utils/getMarkAttrs'
export { default as mergeAttributes } from './src/utils/mergeAttributes'
export { default as fromString } from './src/utils/fromString'

View File

@ -1,3 +0,0 @@
export default function capitalize(value = ''): string {
return value.charAt(0).toUpperCase() + value.slice(1)
}

View File

@ -1,4 +1,8 @@
export default function fromString(value: any) {
if (typeof value !== 'string') {
return value
}
if (value.match(/^\d*(\.\d+)?$/)) {
return Number(value)
}

View File

@ -1,11 +0,0 @@
/// <reference types="cypress" />
import { capitalize } from '@tiptap/core'
describe('capitalize test', () => {
it('capitalize a word', () => {
const capitalized = capitalize('test')
expect(capitalized).to.eq('Test')
})
})

View File

@ -1,5 +0,0 @@
describe('example test', () => {
it('should work', () => {
expect('<p>Example Text</p>').to.eq('<p>Example Text</p>')
})
})

View File

@ -1,41 +1,47 @@
/// <reference types="cypress" />
import { fromString } from '@tiptap/core'
import fromString from '@tiptap/core/src/utils/fromString'
describe('fromString', () => {
it('parse a string', () => {
it('should return a string', () => {
const value = fromString('test')
expect(value).to.eq('test')
})
it('parse a number', () => {
it('should convert to a number', () => {
const value = fromString('1')
expect(value).to.eq(1)
})
it('parse a floating number', () => {
it('should convert to a floating number', () => {
const value = fromString('1.2')
expect(value).to.eq(1.2)
})
it('parse not a number with exponent', () => {
it('should not convert to a number with exponent', () => {
const value = fromString('1e1')
expect(value).to.eq('1e1')
})
it('parse a boolean (true)', () => {
it('should convert to true', () => {
const value = fromString('true')
expect(value).to.eq(true)
})
it('parse a boolean (false)', () => {
it('should convert to false', () => {
const value = fromString('false')
expect(value).to.eq(false)
})
it('should return non-strings', () => {
const value = fromString(null)
expect(value).to.eq(null)
})
})