react-native-date-picker
Version:
A datetime picker for React Native. In-modal or inlined. Supports Android and iOS.
44 lines (33 loc) • 1.21 kB
JavaScript
import { colorToHex } from './colorToHex'
describe('colorToHex', () => {
it('should not change 6 digit hex string ', () => {
expect(colorToHex('#ff00ff')).toEqual('#ff00ff')
})
it('should extend 3 digit hex string to 6 digit ', () => {
expect(colorToHex('#f0f')).toEqual('#ff00ff')
})
it('should transform rgb string to hex', () => {
expect(colorToHex('rgb(255,0,255)')).toEqual('#ff00ff')
})
it('should transform rgba string to hex and ignore alpha part', () => {
expect(colorToHex('rgba(255,0,255,0.5)')).toEqual('#ff00ff')
})
it('should handle rgba string with spaces within', () => {
expect(colorToHex('rgba(255,0 , 255 ,0.5)')).toEqual('#ff00ff')
})
it('should support color names', () => {
expect(colorToHex('green')).toEqual('#008000')
})
it('should throw when empty color', () => {
expect(() => colorToHex('')).toThrow(Error)
})
it('should throw when invalid color', () => {
expect(() => colorToHex('#xxx')).toThrow(Error)
})
it('should throw when null', () => {
expect(() => colorToHex(null)).toThrow(Error)
})
it('return undefined when undefined', () => {
expect(colorToHex(undefined)).toEqual(undefined)
})
})