tiptap/tests/cypress/integration/core/fromString.spec.ts

54 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-11-01 06:45:36 +08:00
/// <reference types="cypress" />
import { fromString } from '@tiptap/core/src/utilities/fromString'
2020-11-01 06:45:36 +08:00
describe('fromString', () => {
2020-11-01 06:56:31 +08:00
it('should return a string', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('test')
expect(value).to.eq('test')
})
it('should return an empty string', () => {
const value = fromString('')
expect(value).to.eq('')
})
2020-11-01 06:56:31 +08:00
it('should convert to a number', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('1')
expect(value).to.eq(1)
})
2020-11-01 06:56:31 +08:00
it('should convert to a floating number', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('1.2')
expect(value).to.eq(1.2)
})
2020-11-01 06:56:31 +08:00
it('should not convert to a number with exponent', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('1e1')
expect(value).to.eq('1e1')
})
2020-11-01 06:56:31 +08:00
it('should convert to true', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('true')
expect(value).to.eq(true)
})
2020-11-01 06:56:31 +08:00
it('should convert to false', () => {
2020-11-01 06:45:36 +08:00
const value = fromString('false')
expect(value).to.eq(false)
})
2020-11-01 06:56:31 +08:00
it('should return non-strings', () => {
const value = fromString(null)
expect(value).to.eq(null)
})
2020-11-01 06:45:36 +08:00
})