refactor tests
This commit is contained in:
@@ -13,10 +13,8 @@ export { default as nodeInputRule } from './src/inputRules/nodeInputRule'
|
|||||||
export { default as markInputRule } from './src/inputRules/markInputRule'
|
export { default as markInputRule } from './src/inputRules/markInputRule'
|
||||||
export { default as markPasteRule } from './src/pasteRules/markPasteRule'
|
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 getSchema } from './src/utils/getSchema'
|
||||||
export { default as generateHTML } from './src/utils/generateHTML'
|
export { default as generateHTML } from './src/utils/generateHTML'
|
||||||
export { default as getHTMLFromFragment } from './src/utils/getHTMLFromFragment'
|
export { default as getHTMLFromFragment } from './src/utils/getHTMLFromFragment'
|
||||||
export { default as getMarkAttrs } from './src/utils/getMarkAttrs'
|
export { default as getMarkAttrs } from './src/utils/getMarkAttrs'
|
||||||
export { default as mergeAttributes } from './src/utils/mergeAttributes'
|
export { default as mergeAttributes } from './src/utils/mergeAttributes'
|
||||||
export { default as fromString } from './src/utils/fromString'
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
export default function capitalize(value = ''): string {
|
|
||||||
return value.charAt(0).toUpperCase() + value.slice(1)
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
export default function fromString(value: any) {
|
export default function fromString(value: any) {
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
if (value.match(/^\d*(\.\d+)?$/)) {
|
if (value.match(/^\d*(\.\d+)?$/)) {
|
||||||
return Number(value)
|
return Number(value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
describe('example test', () => {
|
|
||||||
it('should work', () => {
|
|
||||||
expect('<p>Example Text</p>').to.eq('<p>Example Text</p>')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,41 +1,47 @@
|
|||||||
/// <reference types="cypress" />
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
import { fromString } from '@tiptap/core'
|
import fromString from '@tiptap/core/src/utils/fromString'
|
||||||
|
|
||||||
describe('fromString', () => {
|
describe('fromString', () => {
|
||||||
it('parse a string', () => {
|
it('should return a string', () => {
|
||||||
const value = fromString('test')
|
const value = fromString('test')
|
||||||
|
|
||||||
expect(value).to.eq('test')
|
expect(value).to.eq('test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parse a number', () => {
|
it('should convert to a number', () => {
|
||||||
const value = fromString('1')
|
const value = fromString('1')
|
||||||
|
|
||||||
expect(value).to.eq(1)
|
expect(value).to.eq(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parse a floating number', () => {
|
it('should convert to a floating number', () => {
|
||||||
const value = fromString('1.2')
|
const value = fromString('1.2')
|
||||||
|
|
||||||
expect(value).to.eq(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')
|
const value = fromString('1e1')
|
||||||
|
|
||||||
expect(value).to.eq('1e1')
|
expect(value).to.eq('1e1')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parse a boolean (true)', () => {
|
it('should convert to true', () => {
|
||||||
const value = fromString('true')
|
const value = fromString('true')
|
||||||
|
|
||||||
expect(value).to.eq(true)
|
expect(value).to.eq(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parse a boolean (false)', () => {
|
it('should convert to false', () => {
|
||||||
const value = fromString('false')
|
const value = fromString('false')
|
||||||
|
|
||||||
expect(value).to.eq(false)
|
expect(value).to.eq(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should return non-strings', () => {
|
||||||
|
const value = fromString(null)
|
||||||
|
|
||||||
|
expect(value).to.eq(null)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user