Best JavaScript code snippet using ng-mocks
script.js
Source:script.js
1function main() {2 jogar();3 limparInput();4}5/* Função de envio da requisição */6function fazerGet(url) {7 let request = new XMLHttpRequest()8 request.open("GET", url, true)9 request.send()10 return request11}12const json = (fazerGet("https://us-central1-ss-devops.cloudfunctions.net/rand?min=1&max=300"));13/*console.log(json); para debugar*/14function jogar() {15 var resposta = JSON.parse(json.responseText).value;16 var statusCode = json.status;17 var palpite = document.getElementById("palpite").value;18 var btnJogar = document.getElementById("btnJogar");19 20 if (statusCode == "200") { /* executa o bloco caso a requisiçõa retorne "ok" */21 if(resposta > palpite) {22 mudarDigito();23 apagarDigito();24 document.getElementById("resultado").innerHTML = "à maior";25 }26 else if (resposta < palpite) {27 mudarDigito();28 apagarDigito();29 document.getElementById("resultado").innerHTML = "à menor";30 }31 else if (resposta == palpite) {32 mudarDigitoVerde();33 apagarDigito();34 document.getElementById("resultado").innerHTML = "Você acertou!!!!";35 document.getElementById("resultado").style.color = "#32BF00";36 document.getElementById("novaPartida").style.visibility = "visible"37 document.getElementById("palpite").disabled = true;38 btnJogar.disabled = true;39 btnJogar.style.background = "#DDDDDD";40 /*acionar botão "nova partida" com enter */41 document.addEventListener("keypress", function(e) {42 if(e.key === 'Enter') {43 var btn = document.querySelector("#novaPartida");44 btn.click();45 }46 });47 }48 }49 else {50 mudarDigitoVermelho(); /* em caso de status code diferente de "ok" captura o erro e mostra no led */51 apagarDigitoErro();52 document.getElementById("resultado").innerHTML = "ERRO";53 document.getElementById("resultado").style.color = "#CC3300";54 document.getElementById("novaPartida").style.visibility = "visible"55 document.getElementById("palpite").disabled = true;56 btnJogar.disabled = true;57 btnJogar.style.background = "#DDDDDD";58 document.addEventListener("keypress", function(e) {59 if(e.key === 'Enter') {60 var btn = document.querySelector("#novaPartida");61 btn.click();62 }63 });64 }65}66/*Função para adicionar uma classe mudando o css do algarismo no mostrador de led*/67function mudarDigito() {68 69 /* primeiro digito */70 var element1 = document.querySelector("#segmentos-1");71 var palpite = document.getElementById("palpite").value;72 switch(palpite.charAt(0)) {73 case "0":74 element1.classList.remove(...element1.classList);75 element1.classList.add("segmentos","zero");76 break;77 case "1":78 element1.classList.remove(...element1.classList);79 element1.classList.add("segmentos","um");80 break;81 case "2":82 element1.classList.remove(...element1.classList);83 element1.classList.add("segmentos","dois");84 break;85 case "3":86 element1.classList.remove(...element1.classList);87 element1.classList.add("segmentos","tres");88 break;89 case "4":90 element1.classList.remove(...element1.classList);91 element1.classList.add("segmentos","quatro");92 break;93 case "5":94 element1.classList.remove(...element1.classList);95 element1.classList.add("segmentos","cinco");96 break;97 case "6":98 element1.classList.remove(...element1.classList);99 element1.classList.add("segmentos","seis");100 break;101 case "7":102 element1.classList.remove(...element1.classList);103 element1.classList.add("segmentos","sete");104 break;105 case "8":106 element1.classList.remove(...element1.classList);107 element1.classList.add("segmentos","oito");108 break;109 case "9":110 element1.classList.remove(...element1.classList);111 element1.classList.add("segmentos","nove");112 break;113 }114 115 /* segundo digito */116 var element2 = document.querySelector("#segmentos-2");117 118 switch(palpite.charAt(1)) {119 case "0":120 element2.classList.remove(...element2.classList);121 element2.classList.add("segmentos","zero");122 break;123 case "1":124 element2.classList.remove(...element2.classList);125 element2.classList.add("segmentos","um");126 break;127 case "2":128 element2.classList.remove(...element2.classList);129 element2.classList.add("segmentos","dois");130 break;131 case "3":132 element2.classList.remove(...element2.classList);133 element2.classList.add("segmentos","tres");134 break;135 case "4":136 element2.classList.remove(...element2.classList);137 element2.classList.add("segmentos","quatro");138 break;139 case "5":140 element2.classList.remove(...element2.classList);141 element2.classList.add("segmentos","cinco");142 break;143 case "6":144 element2.classList.remove(...element2.classList);145 element2.classList.add("segmentos","seis");146 break;147 case "7":148 element2.classList.remove(...element2.classList);149 element2.classList.add("segmentos","sete");150 break;151 case "8":152 element2.classList.remove(...element2.classList);153 element2.classList.add("segmentos","oito");154 break;155 case "9":156 element2.classList.remove(...element2.classList);157 element2.classList.add("segmentos","nove");158 break;159 }160 /* terceiro digito */161 var element3 = document.querySelector("#segmentos-3");162 163 switch(palpite.charAt(2)) {164 case "0":165 element3.classList.remove(...element3.classList);166 element3.classList.add("segmentos","zero");167 break;168 case "1":169 element3.classList.remove(...element3.classList);170 element3.classList.add("segmentos","um");171 break;172 case "2":173 element3.classList.remove(...element3.classList);174 element3.classList.add("segmentos","dois");175 break;176 case "3":177 element3.classList.remove(...element3.classList);178 element3.classList.add("segmentos","tres");179 break;180 case "4":181 element3.classList.remove(...element3.classList);182 element3.classList.add("segmentos","quatro");183 break;184 case "5":185 element3.classList.remove(...element3.classList);186 element3.classList.add("segmentos","cinco");187 break;188 case "6":189 element3.classList.remove(...element3.classList);190 element3.classList.add("segmentos","seis");191 break;192 case "7":193 element3.classList.remove(...element3.classList);194 element3.classList.add("segmentos","sete");195 break;196 case "8":197 element3.classList.remove(...element3.classList);198 element3.classList.add("segmentos","oito");199 break;200 case "9":201 element3.classList.remove(...element3.classList);202 element3.classList.add("segmentos","nove");203 break;204 }205}206/*Função para adicionar uma classe mudando o css do algarismo no mostrador de led*/207function mudarDigitoVerde() {208 209 /* primeiro digito */210 var element1 = document.querySelector("#segmentos-1");211 var palpite = document.getElementById("palpite").value;212 switch(palpite.charAt(0)) {213 case "0":214 element1.classList.remove(...element1.classList);215 element1.classList.add("segmentos","zeroGreen");216 break;217 case "1":218 element1.classList.remove(...element1.classList);219 element1.classList.add("segmentos","umGreen");220 break;221 case "2":222 element1.classList.remove(...element1.classList);223 element1.classList.add("segmentos","doisGreen");224 break;225 case "3":226 element1.classList.remove(...element1.classList);227 element1.classList.add("segmentos","tresGreen");228 break;229 case "4":230 element1.classList.remove(...element1.classList);231 element1.classList.add("segmentos","quatroGreen");232 break;233 case "5":234 element1.classList.remove(...element1.classList);235 element1.classList.add("segmentos","cincoGreen");236 break;237 case "6":238 element1.classList.remove(...element1.classList);239 element1.classList.add("segmentos","seisGreen");240 break;241 case "7":242 element1.classList.remove(...element1.classList);243 element1.classList.add("segmentos","seteGreen");244 break;245 case "8":246 element1.classList.remove(...element1.classList);247 element1.classList.add("segmentos","oitoGreen");248 break;249 case "9":250 element1.classList.remove(...element1.classList);251 element1.classList.add("segmentos","noveGreen");252 break;253 }254 255 /* segundo digito */256 var element2 = document.querySelector("#segmentos-2");257 258 switch(palpite.charAt(1)) {259 case "0":260 element2.classList.remove(...element2.classList);261 element2.classList.add("segmentos","zeroGreen");262 break;263 case "1":264 element2.classList.remove(...element2.classList);265 element2.classList.add("segmentos","umGreen");266 break;267 case "2":268 element2.classList.remove(...element2.classList);269 element2.classList.add("segmentos","doisGreen");270 break;271 case "3":272 element2.classList.remove(...element2.classList);273 element2.classList.add("segmentos","tresGreen");274 break;275 case "4":276 element2.classList.remove(...element2.classList);277 element2.classList.add("segmentos","quatroGreen");278 break;279 case "5":280 element2.classList.remove(...element2.classList);281 element2.classList.add("segmentos","cincoGreen");282 break;283 case "6":284 element2.classList.remove(...element2.classList);285 element2.classList.add("segmentos","seisGreen");286 break;287 case "7":288 element2.classList.remove(...element2.classList);289 element2.classList.add("segmentos","seteGreen");290 break;291 case "8":292 element2.classList.remove(...element2.classList);293 element2.classList.add("segmentos","oitoGreen");294 break;295 case "9":296 element2.classList.remove(...element2.classList);297 element2.classList.add("segmentos","noveGreen");298 break;299 }300 /* terceiro digito */301 var element3 = document.querySelector("#segmentos-3");302 303 switch(palpite.charAt(2)) {304 case "0":305 element3.classList.remove(...element3.classList);306 element3.classList.add("segmentos","zeroGreen");307 break;308 case "1":309 element3.classList.remove(...element3.classList);310 element3.classList.add("segmentos","umGreen");311 break;312 case "2":313 element3.classList.remove(...element3.classList);314 element3.classList.add("segmentos","doisGreen");315 break;316 case "3":317 element3.classList.remove(...element3.classList);318 element3.classList.add("segmentos","tresGreen");319 break;320 case "4":321 element3.classList.remove(...element3.classList);322 element3.classList.add("segmentos","quatroGreen");323 break;324 case "5":325 element3.classList.remove(...element3.classList);326 element3.classList.add("segmentos","cincoGreen");327 break;328 case "6":329 element3.classList.remove(...element3.classList);330 element3.classList.add("segmentos","seisGreen");331 break;332 case "7":333 element3.classList.remove(...element3.classList);334 element3.classList.add("segmentos","seteGreen");335 break;336 case "8":337 element3.classList.remove(...element3.classList);338 element3.classList.add("segmentos","oitoGreen");339 break;340 case "9":341 element3.classList.remove(...element3.classList);342 element3.classList.add("segmentos","noveGreen");343 break;344 }345}346/*Função para adicionar uma classe mudando o css do algarismo no mostrador de led*/347function mudarDigitoVermelho() {348 349 /* primeiro digito */350 var element1 = document.querySelector("#segmentos-1");351 var statusCode = json.status;352 353 switch(String(statusCode).charAt(0)) {354 case "0":355 element1.classList.remove(...element1.classList);356 element1.classList.add("segmentos","zeroRed");357 break;358 case "1":359 element1.classList.remove(...element1.classList);360 element1.classList.add("segmentos","umRed");361 break;362 case "2":363 element1.classList.remove(...element1.classList);364 element1.classList.add("segmentos","doisRed");365 break;366 case "3":367 element1.classList.remove(...element1.classList);368 element1.classList.add("segmentos","tresRed");369 break;370 case "4":371 element1.classList.remove(...element1.classList);372 element1.classList.add("segmentos","quatroRed");373 break;374 case "5":375 element1.classList.remove(...element1.classList);376 element1.classList.add("segmentos","cincoRed");377 break;378 case "6":379 element1.classList.remove(...element1.classList);380 element1.classList.add("segmentos","seisRed");381 break;382 case "7":383 element1.classList.remove(...element1.classList);384 element1.classList.add("segmentos","seteRed");385 break;386 case "8":387 element1.classList.remove(...element1.classList);388 element1.classList.add("segmentos","oitoRed");389 break;390 case "9":391 element1.classList.remove(...element1.classList);392 element1.classList.add("segmentos","noveRed");393 break;394 }395 396 /* segundo digito */397 var element2 = document.querySelector("#segmentos-2");398 399 switch(String(statusCode).charAt(1)) {400 case "0":401 element2.classList.remove(...element2.classList);402 element2.classList.add("segmentos","zeroRed");403 break;404 case "1":405 element2.classList.remove(...element2.classList);406 element2.classList.add("segmentos","umRed");407 break;408 case "2":409 element2.classList.remove(...element2.classList);410 element2.classList.add("segmentos","doisRed");411 break;412 case "3":413 element2.classList.remove(...element2.classList);414 element2.classList.add("segmentos","tresRed");415 break;416 case "4":417 element2.classList.remove(...element2.classList);418 element2.classList.add("segmentos","quatroRed");419 break;420 case "5":421 element2.classList.remove(...element2.classList);422 element2.classList.add("segmentos","cincoRed");423 break;424 case "6":425 element2.classList.remove(...element2.classList);426 element2.classList.add("segmentos","seisRed");427 break;428 case "7":429 element2.classList.remove(...element2.classList);430 element2.classList.add("segmentos","seteRed");431 break;432 case "8":433 element2.classList.remove(...element2.classList);434 element2.classList.add("segmentos","oitoRed");435 break;436 case "9":437 element2.classList.remove(...element2.classList);438 element2.classList.add("segmentos","noveRed");439 break;440 }441 /* terceiro digito */442 var element3 = document.querySelector("#segmentos-3");443 444 switch(String(statusCode).charAt(2)) {445 case "0":446 element3.classList.remove(...element3.classList);447 element3.classList.add("segmentos","zeroRed");448 break;449 case "1":450 element3.classList.remove(...element3.classList);451 element3.classList.add("segmentos","umRed");452 break;453 case "2":454 element3.classList.remove(...element3.classList);455 element3.classList.add("segmentos","doisRed");456 break;457 case "3":458 element3.classList.remove(...element.classList);459 element3.classList.add("segmentos","tresRed");460 break;461 case "4":462 element3.classList.remove(...element3.classList);463 element3.classList.add("segmentos","quatroRed");464 break;465 case "5":466 element3.classList.remove(...element3.classList);467 element3.classList.add("segmentos","cincoRed");468 break;469 case "6":470 element3.classList.remove(...element3.classList);471 element3.classList.add("segmentos","seisRed");472 break;473 case "7":474 element3.classList.remove(...element3.classList);475 element3.classList.add("segmentos","seteRed");476 break;477 case "8":478 element3.classList.remove(...element3.classList);479 element3.classList.add("segmentos","oitoRed");480 break;481 case "9":482 element3.classList.remove(...element3.classList);483 element3.classList.add("segmentos","noveRed");484 break;485 }486}487/* muda o valor do input para vazio sempre que o botão "enviar" é acionado */488function limparInput(){489 document.getElementById("palpite").value = "";490}491/* Verifica quantos caracteres tem na string e mostra a quantidade de digitos correspondentes no led */492function apagarDigito(){493 /* verifica tamanho da string e remove os digitos não usados*/494 var palpite = document.getElementById("palpite").value;495 var digito2 = document.getElementById("segmentos-2");496 var digito3 = document.getElementById("segmentos-3");497 var tamanho = palpite.length;498 if (tamanho == 2){499 digito2.style.display = "inline-block";500 digito3.style.display = "none";501 }502 else if (tamanho == 3) {503 digito2.style.display = "inline-block";504 digito3.style.display = "inline-block";505 }506 else if (tamanho == 1) {507 digito2.style.display = "none";508 digito3.style.display = "none";509 }510}511function apagarDigitoErro(){512 /* verifica tamanho da string e remove os digitos não usados*/513 var statusCode = json.status;514 var erro = String(statusCode); 515 var digito2 = document.getElementById("segmentos-2");516 var digito3 = document.getElementById("segmentos-3");517 var tamanho = erro.length;518 if (tamanho == 2){519 digito2.style.display = "inline-block";520 digito3.style.display = "none";521 }522 else if (tamanho == 3) {523 digito2.style.display = "inline-block";524 digito3.style.display = "inline-block";525 }526 else if (tamanho == 1) {527 digito2.style.display = "none";528 digito3.style.display = "none";529 }530}531document.addEventListener("keypress", function(e) {532 if(e.key === 'Enter') {533 var btn = document.querySelector("#btnJogar");534 btn.click();535 }...
linked-list.spec.js
Source:linked-list.spec.js
1describe('LinkedList', () => {2 let linkedList;3 beforeEach(() => {4 linkedList = new LinkedList();5 });6 describe('insert', () => {7 it('should contain the element with key 5 when the element is inserted', () => {8 const element = {9 key: 510 };11 linkedList.insert(element);12 const foundElement = linkedList.contains(element.key);13 expect(foundElement.key).toEqual(element.key);14 });15 it('should contain the elements with keys 5, 10, 14 when the elements is inserted', () => {16 const element1 = {17 key: 518 };19 const element2 = {20 key: 1021 };22 const element3 = {23 key: 1424 };25 linkedList.insert(element1);26 linkedList.insert(element2);27 linkedList.insert(element3);28 const foundElement1 = linkedList.contains(element1.key);29 expect(foundElement1.key).toEqual(element1.key);30 const foundElement2 = linkedList.contains(element2.key);31 expect(foundElement2.key).toEqual(element2.key);32 const foundElement3 = linkedList.contains(element3.key);33 expect(foundElement3.key).toEqual(element3.key);34 });35 it('should increment the size when elements are inserted', () => {36 const element1 = {37 key: 538 };39 const element2 = {40 key: 1041 };42 expect(linkedList.size).toEqual(0);43 linkedList.insert(element1);44 expect(linkedList.size).toEqual(1);45 linkedList.insert(element2);46 expect(linkedList.size).toEqual(2);47 });48 });49 describe('remove', () => {50 it('should remove the element with key 5 when the elements 5, 10, 14 are inserted and 5 is removed', () => {51 const element1 = {52 key: 553 };54 const element2 = {55 key: 1056 };57 const element3 = {58 key: 1459 };60 linkedList.insert(element1);61 linkedList.insert(element2);62 linkedList.insert(element3);63 linkedList.remove(element1.key);64 expect(linkedList.contains(element1.key)).toEqual(null);65 });66 it('should remove the element with key 10 when the elements 5, 10, 14 are inserted and 10 is removed', () => {67 const element1 = {68 key: 569 };70 const element2 = {71 key: 1072 };73 const element3 = {74 key: 1475 };76 linkedList.insert(element1);77 linkedList.insert(element2);78 linkedList.insert(element3);79 linkedList.remove(element2.key);80 expect(linkedList.contains(element2.key)).toEqual(null);81 });82 it('should remove the element with key 14 when the elements 5, 10, 14 are inserted and 14 is removed', () => {83 const element1 = {84 key: 585 };86 const element2 = {87 key: 1088 };89 const element3 = {90 key: 1491 };92 linkedList.insert(element1);93 linkedList.insert(element2);94 linkedList.insert(element3);95 linkedList.remove(element3.key);96 expect(linkedList.contains(element3.key)).toEqual(null);97 });98 it('should decrement the size when elements are removed', () => {99 const element1 = {100 key: 5101 };102 const element2 = {103 key: 10104 };105 const element3 = {106 key: 14107 };108 expect(linkedList.size).toEqual(0);109 linkedList.insert(element1);110 linkedList.insert(element2);111 linkedList.insert(element3);112 expect(linkedList.size).toEqual(3);113 linkedList.remove(element1.key);114 expect(linkedList.size).toEqual(2);115 linkedList.remove(element2.key);116 expect(linkedList.size).toEqual(1);117 linkedList.remove(element3.key);118 expect(linkedList.size).toEqual(0);119 });120 });121 describe('contains', () => {122 it('should return the element with key 5 when the elements 5, 10, 14 are inserted', () => {123 const element1 = {124 key: 5125 };126 const element2 = {127 key: 10128 };129 const element3 = {130 key: 14131 };132 linkedList.insert(element1);133 linkedList.insert(element2);134 linkedList.insert(element3);135 const foundElement1 = linkedList.contains(element1.key);136 expect(foundElement1.key).toEqual(element1.key);137 });138 it('should return the element with key 10 when the elements 5, 10, 14 are inserted', () => {139 const element1 = {140 key: 5141 };142 const element2 = {143 key: 10144 };145 const element3 = {146 key: 14147 };148 linkedList.insert(element1);149 linkedList.insert(element2);150 linkedList.insert(element3);151 const foundElement2 = linkedList.contains(element2.key);152 expect(foundElement2.key).toEqual(element2.key);153 });154 it('should return the element with key 14 when the elements 5, 10, 14 are inserted', () => {155 const element1 = {156 key: 5157 };158 const element2 = {159 key: 10160 };161 const element3 = {162 key: 14163 };164 linkedList.insert(element1);165 linkedList.insert(element2);166 linkedList.insert(element3);167 const foundElement3 = linkedList.contains(element3.key);168 expect(foundElement3.key).toEqual(element3.key);169 });170 it('should return null when the element with key 20 is searched for and only elements 5, 10, 14 are inserted', () => {171 const element1 = {172 key: 5173 };174 const element2 = {175 key: 10176 };177 const element3 = {178 key: 14179 };180 linkedList.insert(element1);181 linkedList.insert(element2);182 linkedList.insert(element3);183 const foundElement1 = linkedList.contains(20);184 expect(foundElement1).toEqual(null);185 });186 });187 describe('size', () => {188 it('should return 0 when no elements have been inserted', () => {189 expect(linkedList.size).toEqual(0);190 });191 it('should return 1 when 1 element has been inserted', () => {192 const element1 = {193 key: 5194 };195 linkedList.insert(element1);196 expect(linkedList.size).toEqual(1);197 });198 it('should return 3 when 3 elements have been inserted', () => {199 expect(linkedList.size).toEqual(0);200 const element1 = {201 key: 5202 };203 const element2 = {204 key: 10205 };206 const element3 = {207 key: 14208 };209 linkedList.insert(element1);210 linkedList.insert(element2);211 linkedList.insert(element3);212 expect(linkedList.size).toEqual(3);213 });214 it('should return 2 when 3 elements are inserted and one is removed', () => {215 expect(linkedList.size).toEqual(0);216 const element1 = {217 key: 5218 };219 const element2 = {220 key: 10221 };222 const element3 = {223 key: 14224 };225 linkedList.insert(element1);226 linkedList.insert(element2);227 linkedList.insert(element3);228 expect(linkedList.size).toEqual(3);229 linkedList.remove(element1.key);230 expect(linkedList.size).toEqual(2);231 });232 it('should return 0 when 3 elements have been inserted and 3 are removed', () => {233 const element1 = {234 key: 5235 };236 const element2 = {237 key: 10238 };239 const element3 = {240 key: 14241 };242 expect(linkedList.size).toEqual(0);243 linkedList.insert(element1);244 linkedList.insert(element2);245 linkedList.insert(element3);246 expect(linkedList.size).toEqual(3);247 linkedList.remove(element1.key);248 expect(linkedList.size).toEqual(2);249 linkedList.remove(element2.key);250 expect(linkedList.size).toEqual(1);251 linkedList.remove(element3.key);252 expect(linkedList.size).toEqual(0);253 });254 });...
products-modal-3.js
Source:products-modal-3.js
1const openProductModalBtn3 = document.querySelector('.products-btn-3');2const closeProductModalBtn3 = document.querySelector('.products-close-btn-3');3const productModal3 = document.querySelector('.products-backdrop-3');4const productModalWindow3 = document.querySelector('.products-modal-3');5const productModalForm3 = document.querySelector('.products-form-3');6const animateElement3_1 = document.querySelector('.products__form-title-3');7const animateElement3_2 = document.querySelector('.products__form-wrap-img-3');8const animateElement3_3 = document.querySelector('.products__form-img-3');9const animateElement3_4 = document.querySelector(10 '.products__form-mcrlmnt-list-3'11);12const animateElement3_5 = document.querySelector(13 '.products__description-list-3'14);15const animateElement3_6 = document.querySelector(16 '.products__description-title-3'17);18const animateElement3_7 = document.querySelector('.products__form-field-3');19const animateElement3_8 = document.querySelector(20 '.products__form-mcrlmnt-text-3'21);22const animateElement3_9 = document.querySelector('.circle3_1');23const animateElement3_10 = document.querySelector('.circle3_2');24const animateElement3_11 = document.querySelector('.circle3_3');25const animateElement3_12 = document.querySelector('.circle3_4');26openProductModalBtn3.addEventListener('click', function () {27 productModal3.classList.remove('is-hidden');28 animateElement3_1.classList.add('animation-fade-in');29 animateElement3_2.classList.add('animation-fade-in');30 animateElement3_3.classList.add('animation-ping-pong');31 animateElement3_4.classList.add('animation-fade-in');32 animateElement3_5.classList.add('animation-fade-in');33 animateElement3_6.classList.add('animation-fade-in');34 animateElement3_7.classList.add('animation-fade-in');35 animateElement3_8.classList.add('animation-rotate');36 animateElement3_9.classList.add('animation-rotate');37 animateElement3_10.classList.add('animation-rotate');38 animateElement3_11.classList.add('animation-rotate');39 animateElement3_12.classList.add('animation-rotate');40});41closeProductModalBtn3.addEventListener('click', function () {42 productModal3.classList.toggle('is-hidden');43 animateElement3_1.classList.toggle('animation-fade-in');44 animateElement3_2.classList.toggle('animation-fade-in');45 animateElement3_3.classList.toggle('animation-ping-pong');46 animateElement3_4.classList.toggle('animation-fade-in');47 animateElement3_5.classList.toggle('animation-fade-in');48 animateElement3_6.classList.toggle('animation-fade-in');49 animateElement3_7.classList.toggle('animation-fade-in');50 animateElement3_8.classList.toggle('animation-rotate');51 animateElement3_9.classList.remove('animation-rotate');52 animateElement3_10.classList.remove('animation-rotate');53 animateElement3_11.classList.remove('animation-rotate');54 animateElement3_12.classList.remove('animation-rotate');55 productModalForm3.reset();56});57productModal3.addEventListener('click', e => {58 const closeProductModal3 = e.composedPath().includes(productModalWindow3);59 if (!closeProductModal3) {60 productModal3.classList.add('is-hidden');61 animateElement3_1.classList.toggle('animation-fade-in');62 animateElement3_2.classList.toggle('animation-fade-in');63 animateElement3_3.classList.toggle('animation-ping-pong');64 animateElement3_4.classList.toggle('animation-fade-in');65 animateElement3_5.classList.toggle('animation-fade-in');66 animateElement3_6.classList.toggle('animation-fade-in');67 animateElement3_7.classList.toggle('animation-fade-in');68 animateElement3_8.classList.toggle('animation-rotate');69 animateElement3_9.classList.remove('animation-rotate');70 animateElement3_10.classList.remove('animation-rotate');71 animateElement3_11.classList.remove('animation-rotate');72 animateElement3_12.classList.remove('animation-rotate');73 productModalForm3.reset();74 }75});76document.addEventListener('keydown', function (e) {77 if (e.key === 'Escape') {78 productModal3.classList.add('is-hidden');79 animateElement3_1.classList.toggle('animation-fade-in');80 animateElement3_2.classList.toggle('animation-fade-in');81 animateElement3_3.classList.toggle('animation-ping-pong');82 animateElement3_4.classList.toggle('animation-fade-in');83 animateElement3_5.classList.toggle('animation-fade-in');84 animateElement3_6.classList.toggle('animation-fade-in');85 animateElement3_7.classList.toggle('animation-fade-in');86 animateElement3_8.classList.toggle('animation-rotate');87 animateElement3_9.classList.remove('animation-rotate');88 animateElement3_10.classList.remove('animation-rotate');89 animateElement3_11.classList.remove('animation-rotate');90 animateElement3_12.classList.remove('animation-rotate');91 productModalForm3.reset();92 }...
Using AI Code Generation
1import { MockRender } from 'ng-mocks';2import { AppComponent } from './app.component';3describe('AppComponent', () => {4 it('should create the app', () => {5 const fixture = MockRender(AppComponent);6 const app = fixture.point.componentInstance;7 expect(app).toBeTruthy();8 });9});
Using AI Code Generation
1import { element3 } from 'ng-mocks';2describe('MyComponent', () => {3 let fixture: ComponentFixture<MyComponent>;4 beforeEach(() => {5 fixture = TestBed.configureTestingModule({6 }).createComponent(MyComponent);7 });8 it('should render', () => {9 const element = element3(fixture, 'my-element');10 expect(element).toBeDefined();11 });12});13import 'ng-mocks';
Using AI Code Generation
1import { element3 } from 'ng-mocks';2import { TestComponent } from './test';3describe('element3', () => {4 it('should work', () => {5 const fixture = new MockRender(TestComponent);6 const element = element3(fixture);7 expect(element).not.toBe(null);8 });9});10The element3() method is used to get the first element of the fixture, which is the root element of the component. This method is used to test the component in
Using AI Code Generation
1var element3 = ngMocks.element3;2var fixture = ngMocks.find('fixture');3var component = ngMocks.find('component');4var directive = ngMocks.find('directive');5var pipe = ngMocks.find('pipe');6var service = ngMocks.find('service');7var module = ngMocks.find('module');8var componentInstance = ngMocks.instance('component');9var directiveInstance = ngMocks.instance('directive');10var pipeInstance = ngMocks.instance('pipe');11var serviceInstance = ngMocks.instance('service');12var moduleInstance = ngMocks.instance('module');13var fixture = ngMocks.find('fixture');14var component = ngMocks.find('component');15var directive = ngMocks.find('directive');16var pipe = ngMocks.find('pipe');17var service = ngMocks.find('service');18var module = ngMocks.find('module');19var componentInstance = ngMocks.instance('component');20var directiveInstance = ngMocks.instance('directive');21var pipeInstance = ngMocks.instance('pipe');22var serviceInstance = ngMocks.instance('service');23var moduleInstance = ngMocks.instance('module');24var fixture = ngMocks.find('fixture');25var component = ngMocks.find('component');26var directive = ngMocks.find('directive');27var pipe = ngMocks.find('pipe');28var service = ngMocks.find('service');29var module = ngMocks.find('module');30var componentInstance = ngMocks.instance('component');31var directiveInstance = ngMocks.instance('directive');32var pipeInstance = ngMocks.instance('pipe');33var serviceInstance = ngMocks.instance('service');34var moduleInstance = ngMocks.instance('module');35var fixture = ngMocks.find('fixture');36var component = ngMocks.find('component');37var directive = ngMocks.find('directive');38var pipe = ngMocks.find('pipe');39var service = ngMocks.find('service');40var module = ngMocks.find('module');41var componentInstance = ngMocks.instance('component');42var directiveInstance = ngMocks.instance('directive');43var pipeInstance = ngMocks.instance('pipe');44var serviceInstance = ngMocks.instance('service');45var moduleInstance = ngMocks.instance('module');46var fixture = ngMocks.find('fixture');47var component = ngMocks.find('component');
Using AI Code Generation
1import { element3 } from 'ng-mocks';2describe('MyComponent', () => {3 it('should be able to find the element', () => {4 const fixture = MockRender(MyComponent);5 const element = element3('div', fixture);6 expect(element).toBeTruthy();7 });8});9import { ngMocks } from 'ng-mocks';10import { TestBed } from '@angular/core/testing';11TestBed.configureTestingModule({12 imports: [MyModule],13 providers: ngMocks.guts(),14});15import { ngMocks } from 'ng-mocks';16import { TestBed } from '@angular/core/testing';17TestBed.configureTestingModule({18 imports: [MyModule],19 providers: ngMocks.guts(),20});21import { ngMocks } from 'ng-mocks';22import { TestBed } from '@angular/core/testing';23TestBed.configureTestingModule({24 imports: [MyModule],25 providers: ngMocks.guts(),26});27import { ngMocks } from 'ng-mocks';28import { TestBed } from '@angular/core/testing';29TestBed.configureTestingModule({30 imports: [MyModule],31 providers: ngMocks.guts(),32});33import { ngMocks } from 'ng-mocks';34import { TestBed } from '@angular/core/testing';35TestBed.configureTestingModule({36 imports: [MyModule],37 providers: ngMocks.guts(),38});39import { ngMocks } from 'ng-mocks';40import { TestBed } from '@angular/core/testing';41TestBed.configureTestingModule({42 imports: [MyModule],43 providers: ngMocks.guts(),44});45import { ngMocks } from 'ng-mocks';46import { TestBed } from '@angular/core/testing';47TestBed.configureTestingModule({48 imports: [MyModule],49 providers: ngMocks.guts(),50});51import { ngMocks } from
Using AI Code Generation
1import { element3 } from 'ng-mocks';2const fixture = TestBed.createComponent(MyComponent);3const myComponent = fixture.componentInstance;4const myElement = element3('my-selector', fixture);5import { ngMocks } from 'ng-mocks';6const fixture = TestBed.createComponent(MyComponent);7const myComponent = ngMocks.findInstance(MyComponent);8const myComponent = ngMocks.findInstance(MyComponent, fixture);9import { ngMocks } from 'ng-mocks';10const fixture = TestBed.createComponent(MyComponent);11const myComponent = ngMocks.findInstance(MyComponent);12const myComponent = ngMocks.findInstance(MyComponent, fixture);13import { ngMocks } from 'ng-mocks';14const fixture = TestBed.createComponent(MyComponent);15const myComponent = ngMocks.findInstance(MyComponent);16const myComponent = ngMocks.findInstance(MyComponent, fixture);17import { ngMocks } from 'ng-mocks';18const fixture = TestBed.createComponent(MyComponent);19const myComponent = ngMocks.findInstance(MyComponent);20const myComponent = ngMocks.findInstance(MyComponent, fixture);21import { ngMocks } from 'ng-mocks';22const fixture = TestBed.createComponent(MyComponent);23const myComponent = ngMocks.findInstance(MyComponent);24const myComponent = ngMocks.findInstance(MyComponent, fixture);25import { ngMocks } from 'ng-mocks';26const fixture = TestBed.createComponent(MyComponent);27const myComponent = ngMocks.findInstance(MyComponent);28const myComponent = ngMocks.findInstance(MyComponent, fixture);29import { ngMocks } from 'ng-mocks';30const fixture = TestBed.createComponent(MyComponent);31const myComponent = ngMocks.findInstance(MyComponent);32const myComponent = ngMocks.findInstance(MyComponent, fixture);33import { ngMocks } from 'ng-mocks';34const fixture = TestBed.createComponent(MyComponent);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!