fix: parsePhone fn when no phone
This commit is contained in:
parent
d9d6819390
commit
e2304396d8
|
@ -1,4 +1,7 @@
|
||||||
export default function (phone, prefix = 34) {
|
export default function (phone, prefix = 34) {
|
||||||
|
if (!phone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (phone.startsWith('+')) {
|
if (phone.startsWith('+')) {
|
||||||
return `${phone.slice(1)}`;
|
return `${phone.slice(1)}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,14 @@ import { describe, it, expect } from 'vitest';
|
||||||
import parsePhone from 'src/filters/parsePhone';
|
import parsePhone from 'src/filters/parsePhone';
|
||||||
|
|
||||||
describe('parsePhone filter', () => {
|
describe('parsePhone filter', () => {
|
||||||
|
it('no phone', () => {
|
||||||
|
const resultado = parsePhone(null, '34');
|
||||||
|
expect(resultado).toBe(undefined);
|
||||||
|
});
|
||||||
|
it('no phone and no prefix', () => {
|
||||||
|
const resultado = parsePhone(null, null);
|
||||||
|
expect(resultado).toBe(undefined);
|
||||||
|
});
|
||||||
it("adds prefix +34 if it doesn't have one", () => {
|
it("adds prefix +34 if it doesn't have one", () => {
|
||||||
const resultado = parsePhone('123456789', '34');
|
const resultado = parsePhone('123456789', '34');
|
||||||
expect(resultado).toBe('34123456789');
|
expect(resultado).toBe('34123456789');
|
||||||
|
|
Loading…
Reference in New Issue