随笔分类 - Unit Testing
摘要:While not all of accessibility testing of a web application can be automated, much of it can be and quite easily using axe-core and jest-axe. Let’s se
阅读全文
摘要:You can use 'rerender' for a component when its props changed. Then if you wnat to check the alert message has gone when we rerender, you need to use
阅读全文
摘要:The User Event module is part of the Testing Library family of tools and lets you fire events on DOM nodes that more closely resemble the way your use
阅读全文
摘要:The fireEvent utility in React Testing Library supports all the events that you regularly use in the web (change, click, etc.). Let’s see how we can t
阅读全文
摘要:While you’re writing your tests it can be helpful to see what the DOM looks like. You can do this with React Testing Library’s debug function which wi
阅读全文
摘要:Component: import React from 'react' function FavoriteNumber({ min = 1, max = 9 }) { const [number, setNumber] = React.useState(0) const [numberEntere
阅读全文
摘要:We can use 'jest.spyOn', similr to 'spyOn' in Jasmine. jest.spyOn(utils, 'getWinner') We get 'getWinner' as a method. Jest has mockImplementation: //
阅读全文
摘要:Epic: import { ofType } from 'redux-observable' import { of, concat, merge, fromEvent, race, forkJoin } from 'rxjs' const buildAPI = (apiBase, perPage
阅读全文
摘要:Component to be tested: <ng-template #defaultPlaceholder> Loading... </ng-template> <div class="loading-container" *ngIf="loading$ | async"> <ng-conta
阅读全文
摘要:Component: <div class="loading-placeholder" [ngClass]="extraClass"> <ng-container *ngIf="loadingService.config.showContent"> <ng-content></ng-c
阅读全文
摘要:Component: import { Component, OnInit } from "@angular/core"; import { TwainService } from "../twain.service"; import { Observable, of } from "rxjs";
阅读全文
摘要:The component we test against: import {Component, OnInit} from '@angular/core'; import {Course} from "../model/course"; import {Observable} from "rxjs
阅读全文
摘要:In this post, we are going to see how to use 'fakeAsync' to test async code in Angular Context. fakeAsync using Zoom.js underhook, it detects all the
阅读全文
摘要:The smart component we want to test: import {Component, OnInit} from '@angular/core'; import {Course} from "../model/course"; import {Observable} from
阅读全文
摘要:In Angular version 8, TestBed.get was deprecated. In Angular version 9, we see why: TestBed.inject<T> is introduced as a type-safe replacement. There
阅读全文
摘要:Setting up a Presentational Component: import {Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation} from '@angular/core'; import {Course
阅读全文
摘要:How to test a service The service we want to test against: import {Injectable} from '@angular/core'; import {LoggerService} from './logger.service'; @
阅读全文
摘要:it ('should add two numbers', () => { const logger = jasmine.createSpyObj('LoggerService', ['log']) // logger.log.and.returnValue(); const calculator
阅读全文
摘要:beforeEach(() => { contextStub = { debug: false, engine: jasmine.createSpyObj('engine', [ 'createCollection', 'createContext', 'createSchematic', 'createSourceFromUrl', 'transformOptions', 'executePos
阅读全文
摘要:It is recommened to write unit testing with Mockito in Spring framework, because it is much faster with Spring framework test. But in case you can doi
阅读全文