-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathchallenge.test.js
More file actions
211 lines (171 loc) · 6.5 KB
/
challenge.test.js
File metadata and controls
211 lines (171 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { describe, it, expect } from "vitest";
const {
identificarPrimitivos,
diferenciarStringNumber,
explorarNull,
compararNullUndefined,
crearSymbolYBigInt,
crearObjeto,
trabajarConArreglos,
funcionComoValor,
clasificarTipo,
} = require("./challenge.js");
describe("Reto 02 - Tipos de datos: primitivos vs complejos", () => {
describe("Reto 1: identificarPrimitivos", () => {
it('debe retornar "string" para texto', () => {
expect(identificarPrimitivos().texto).toBe("string");
});
it('debe retornar "number" para numero', () => {
expect(identificarPrimitivos().numero).toBe("number");
});
it('debe retornar "boolean" para booleano', () => {
expect(identificarPrimitivos().booleano).toBe("boolean");
});
it('debe retornar "object" para nulo (caso especial de typeof null)', () => {
expect(identificarPrimitivos().nulo).toBe("object");
});
it('debe retornar "undefined" para indefinido', () => {
expect(identificarPrimitivos().indefinido).toBe("undefined");
});
it('debe retornar "symbol" para simbolo', () => {
expect(identificarPrimitivos().simbolo).toBe("symbol");
});
it('debe retornar "bigint" para grande', () => {
expect(identificarPrimitivos().grande).toBe("bigint");
});
});
describe("Reto 2: diferenciarStringNumber", () => {
it('debe identificar "42" como string', () => {
const resultado = diferenciarStringNumber("42");
expect(resultado.tipo).toBe("string");
expect(resultado.esString).toBe(true);
expect(resultado.esNumber).toBe(false);
});
it("debe identificar 42 como number", () => {
const resultado = diferenciarStringNumber(42);
expect(resultado.tipo).toBe("number");
expect(resultado.esString).toBe(false);
expect(resultado.esNumber).toBe(true);
});
it("debe identificar true como ni string ni number", () => {
const resultado = diferenciarStringNumber(true);
expect(resultado.tipo).toBe("boolean");
expect(resultado.esString).toBe(false);
expect(resultado.esNumber).toBe(false);
});
});
describe("Reto 3: explorarNull", () => {
it("el valor debe ser null", () => {
expect(explorarNull().valor).toBeNull();
});
it('typeof null debe ser "object" (caso especial)', () => {
expect(explorarNull().tipo).toBe("object");
});
it("esNull debe ser true", () => {
expect(explorarNull().esNull).toBe(true);
});
});
describe("Reto 4: compararNullUndefined", () => {
it("sinAsignar debe ser undefined", () => {
expect(compararNullUndefined().sinAsignar).toBeUndefined();
});
it("vacio debe ser null", () => {
expect(compararNullUndefined().vacio).toBeNull();
});
it('tipoSinAsignar debe ser "undefined"', () => {
expect(compararNullUndefined().tipoSinAsignar).toBe("undefined");
});
it('tipoVacio debe ser "object"', () => {
expect(compararNullUndefined().tipoVacio).toBe("object");
});
it("null == undefined debe ser true (igualdad débil)", () => {
expect(compararNullUndefined().sonIguales).toBe(true);
});
it("null === undefined debe ser false (igualdad estricta)", () => {
expect(compararNullUndefined().sonEstrictamenteIguales).toBe(false);
});
});
describe("Reto 5: crearSymbolYBigInt", () => {
it('tipoSymbol debe ser "symbol"', () => {
expect(crearSymbolYBigInt().tipoSymbol).toBe("symbol");
});
it('tipoBigInt debe ser "bigint"', () => {
expect(crearSymbolYBigInt().tipoBigInt).toBe("bigint");
});
it('descripcionSymbol debe ser "miID"', () => {
expect(crearSymbolYBigInt().descripcionSymbol).toBe("miID");
});
it("valorBigInt debe ser 9007199254740991n", () => {
expect(crearSymbolYBigInt().valorBigInt).toBe(9007199254740991n);
});
});
describe("Reto 6: crearObjeto", () => {
it("persona debe tener nombre, edad y activo", () => {
const { persona } = crearObjeto();
expect(persona.nombre).toBe("Juan");
expect(persona.edad).toBe(42);
expect(persona.activo).toBe(true);
});
it('tipoPersona debe ser "object"', () => {
expect(crearObjeto().tipoPersona).toBe("object");
});
it("propiedades debe contener las claves correctas", () => {
expect(crearObjeto().propiedades).toEqual(["nombre", "edad", "activo"]);
});
});
describe("Reto 7: trabajarConArreglos", () => {
it("el arreglo debe tener 4 elementos", () => {
expect(trabajarConArreglos().largo).toBe(4);
});
it("esArreglo debe ser true", () => {
expect(trabajarConArreglos().esArreglo).toBe(true);
});
it("el arreglo debe contener los valores correctos", () => {
expect(trabajarConArreglos().arreglo).toEqual([1, "dos", true, null]);
});
it("los tipos deben ser correctos para cada elemento", () => {
expect(trabajarConArreglos().tipos).toEqual([
"number",
"string",
"boolean",
"object",
]);
});
});
describe("Reto 8: funcionComoValor", () => {
it('tipoFuncion debe ser "function"', () => {
expect(funcionComoValor().tipoFuncion).toBe("function");
});
it('resultado debe ser "Hola, JavaScript!"', () => {
expect(funcionComoValor().resultado).toBe("Hola, JavaScript!");
});
});
describe("Reto 9: clasificarTipo", () => {
it('un string debe clasificarse como "primitivo"', () => {
expect(clasificarTipo("hola").clasificacion).toBe("primitivo");
});
it('un number debe clasificarse como "primitivo"', () => {
expect(clasificarTipo(42).clasificacion).toBe("primitivo");
});
it('null debe clasificarse como "primitivo"', () => {
const resultado = clasificarTipo(null);
expect(resultado.tipo).toBe("object");
expect(resultado.clasificacion).toBe("primitivo");
});
it('un objeto debe clasificarse como "complejo"', () => {
expect(clasificarTipo({ a: 1 }).clasificacion).toBe("complejo");
});
it('un arreglo debe clasificarse como "complejo"', () => {
expect(clasificarTipo([1, 2]).clasificacion).toBe("complejo");
});
it('una función debe clasificarse como "complejo"', () => {
expect(clasificarTipo(function () {}).clasificacion).toBe("complejo");
});
it('un boolean debe clasificarse como "primitivo"', () => {
expect(clasificarTipo(true).clasificacion).toBe("primitivo");
});
it('undefined debe clasificarse como "primitivo"', () => {
expect(clasificarTipo(undefined).clasificacion).toBe("primitivo");
});
});
});