国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Inhaltsverzeichnis
Table of contents
What is testing?
Different tests look at different parts of the project
Unit testing
Integration testing
End-to-end (E2E) testing
Accessibility testing
Visual regression testing
Performance testing
Wrapping up
Heim Web-Frontend CSS-Tutorial Front-End-Tests sind für alle

Front-End-Tests sind für alle

Mar 23, 2025 am 09:33 AM

Front-End Testing is For Everyone

Testing is one of those things that you either get super excited about or kinda close your eyes and walk away. Whichever camp you fall into, I’m here to tell you that front-end testing is for everyone. In fact, there are many types of tests and perhaps that is where some of the initial fear or confusion comes from.

I’m going to cover the most popular and widely used types of tests in this article. This might be nothing new to some of you, but it can at least serve as a refresher. Either way, my goal is that you’re able to walk away with a good idea of the different types of tests out there. Unit. Integration. Accessibility. Visual regression. These are the sorts of things we’ll look at together.

And not just that! We’ll also point out the libraries and frameworks that are used for each type of test, like Mocha. Jest, Puppeteer, and Cypress, among others. And don’t worry?—?I’ll avoid a bunch of technical jargon. That said, you should have some front-end development experience to understand the examples we’re going to cover.

OK, let’s get started!

Table of contents

  • What is testing?
  • Different tests look at different parts of the project
  • Unit testing
  • Integration testing
  • End-to-end (E2E) testing
  • Accessibility testing
  • Visual regression testing
  • Performance testing
  • Wrapping up

What is testing?

Software testing is an investigation conducted to provide stakeholders with information about the quality of the software product or service under test.

Cem Kaner, “Exploratory Testing” (November 17, 2006)

At its most basic, testing is an automated tool that finds errors in your development as early as possible. That way, you’re able to fix those issues before they make it into production. Tests also serve as a reminder that you may have forgotten to check your own work in a certain area, say accessibility.

In short, front-end testing validates that what people see on the site and the features they use on it work as intended.

Front-end testing is for the client side of your application. For example, front-end tests can validate that pressing a “Delete” button properly removes an item from the screen. However, it won’t necessarily check if the item was actually removed from the database?—?that sort of thing would be covered during back-end testing.

That’s testing in a nutshell: we want to catch errors on the client side and fix them before code is deployed.

Different tests look at different parts of the project

Different types of tests cover different aspects of a project. Nevertheless, it is important to differentiate them and understand the role of each type. Confusing which tests do what makes for a messy, unreliable testing suit.

Ideally, you’d use several different types of tests to surface different types of possible issues. Some test types have a test coverage analytic that shows just how much of your code (as a percentage) is looked at by that particular test. That’s a great feature, and while I’ve seen developers aim for 100% coverage, I wouldn’t rely on that metric alone. The most important thing is to make sure all possible edge cases are covered and taken into account.

So, with that, let’s turn our attention to the different types of testing. Remember, it’s not so much that you’re expected to use each and every one of these. It’s about being able to differentiate the tests so that you know which ones to use in certain circumstances.

Unit testing

  • Level: Low
  • Scope: Tests the functions and methods of an application.
  • Possible tools:, AVA, Jasmine, Jest, Karma, Mocha

Unit testing is the most basic building block for testing. It looks at individual components and ensures they work as expected. This sort of testing is crucial for any front-end application because, with it, your components are tested against how they’re expected to behave, which leads to a much more reliable codebase and app. This is also where things like edge cases can be considered and covered.

Unit tests are particularly great for testing APIs. But rather than making calls to a live API, hardcoded (or “mocked”) data makes sure that your test runs are always consistent at all time.

Let’s take a super simple (and primitive) function as an example:

const sayHello = (name) => {
  if (!name) {
    return "Hello human!";
  }

  return `Hello ${name}!`;
};

Again, this is a basic case, but you can see that it covers a small edge case where someone may have neglected to provide a first name to the application. If there’s a name, we’ll get “Hello ${name}!” where ${name} is what we expect the person to have provided.

“Um, why do we need to test for something small like that?” you might wonder. There are some very important reasons for this:

  • It forces you to think deeply about the possible outcomes of your function. More often than not, you really do discover edge cases which helps you cover them in your code.
  • Some part of your code can rely on this edge case, and if someone comes and deletes something important, the test will warn them that this code is important and cannot be removed.

Unit tests are often small and simple. Here’s an example:

describe("sayHello function", () => {
  it("should return the proper greeting when a user doesn't pass a name", () => {
    expect(sayHello()).toEqual("Hello human!")
  })

  it("should return the proper greeting with the name passed", () => {
    expect(sayHello("Evgeny")).toEqual("Hello Evgeny!")
  })
})

describe and it are just syntactic sugar. The most important lines with expect and toEqual. describe and it breaks the test into logical blocks that are printed to the terminal. The expect function accepts the input we want to validate, while toEqual accepts the desired output. There are a lot of different functions and methods you can use to test your application.

Let’s say we’re working with Jest, a library for writing units. In the example above, Jest will display the sayHello function as a title in the terminal. Everything inside an it function is considered as a single test and is reported in the terminal below the function title, making everything very easy to read.

Integration testing

  • Level: Medium
  • Scope: Tests Interactions between units.
  • Possible tools: AVA, Jest, Testing Library

If unit tests check the behavior of a block, integration tests make sure that blocks work flawlessly together. That makes Integration testing super important because it opens up testing interactions between components. It’s very rare (if ever) that an application is composed of isolated pieces that function by themselves. That’s why we rely on integration tests.

We go back to the function we unit tested, but this time use it in a simple React application. Let’s say that clicking a button triggers a greeting to appear on the screen. That means a test involves not only the function but also the HTML DOM and a button’s functionality. We want to test how all these parts play together.

Here’s the code for a component we’re testing:

export const Greeting = () => {  
  const [showGreeting, setShowGreeting] = useState(false);  

 return (  
   <div>  
     <p data-test>{showGreeting && sayHello()}</p>  
     <button data-test onClick={() => setShowGreeting(true)}>Show Greeting</button>  
   </div>
 );  
};

Here’s the integration test:

describe('<Greeting />', () => {  
  it('shows correct greeting', () => {  
    const screen = render(<Greeting />);  
     const greeting = screen.getByTestId('greeting');  
     const button = screen.getByTestId('show-greeting-button');  

     expect(greeting.textContent).toBe('');  
     fireEvent.click(button);  
     expect(greeting.textContent).toBe('Hello human!');  
 });  
});

We already know describe and it from our unit test. They break tests up into logical parts. We have the render function that displays a component in the special emulated DOM so we can test interactions with the component without touching the real DOM?—?otherwise, it can be costly.

Next up, the test queries

and

Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276
Was ist der Unterschied zwischen Anzeige: Inline, Anzeige: Block und Anzeige: Inline-Block? Was ist der Unterschied zwischen Anzeige: Inline, Anzeige: Block und Anzeige: Inline-Block? Jul 11, 2025 am 03:25 AM

ThemaNDiffercesbetweenplay: Inline, Block, Andinline-Blockinhtml/CsSarelayoutBehavior, Spaceusage und Stylingcontrol.1.inlineelementsflowwithtext, Don'tstartonNewlines, Ignorewidth/HeighthThorchingstyhorching-/idelthorchorching/ardaldhordhortaliTalding/ardaldhordelthortex

Das Styling besuchte Links unterschiedlich mit CSS Das Styling besuchte Links unterschiedlich mit CSS Jul 11, 2025 am 03:26 AM

Durch das Festlegen des von Ihnen besuchten Links k?nnen Sie die Benutzererfahrung verbessern, insbesondere in inhaltsintensiven Websites, um den Benutzern dabei zu helfen, sich besser zu navigieren. 1. Verwenden Sie CSS: Besuchte Pseudoklasse, um den Stil des besuchten Links wie Farb?nderungen zu definieren. 2. Beachten Sie, dass der Browser nur eine ?nderung einiger Attribute aufgrund von Datenschutzbeschr?nkungen erm?glicht. 3. Die Farbauswahl sollte mit dem Gesamtstil koordiniert werden, um abrupte abrupt zu werden. 4. Das mobile Terminal zeigt diesen Effekt m?glicherweise nicht an. Es wird empfohlen, ihn mit anderen visuellen Eingabeaufforderungen wie Icon -Auxiliary -Logos zu kombinieren.

Erstellen von benutzerdefinierten Formen mit CSS-Clip-Pfad Erstellen von benutzerdefinierten Formen mit CSS-Clip-Pfad Jul 09, 2025 am 01:29 AM

Verwenden Sie das Clip-Pfad-Attribut von CSS, um Elemente in benutzerdefinierte Formen wie Dreiecke, kreisf?rmige Kerben, Polygone usw. zu erregen, ohne sich auf Bilder oder SVGs zu verlassen. Zu den Vorteilen geh?ren: 1.. Unterstützt eine Vielzahl von Grundformen wie Circle, Ellipse, Polygon usw.; 2. reagierende Anpassung und anpassbar an mobile Terminals; 3. Einfach zu animation und kann mit Hover oder JavaScript kombiniert werden, um dynamische Effekte zu erzielen. 4. Es wirkt sich nicht auf den Layoutfluss aus und erfüllt nur den Anzeigebereich. H?ufige Verwendungen sind z. B. kreisf?rmiger Clip-Pfad: Kreis (50pxatcenter) und Dreieck-Clip-Pfad: Polygon (50%0%, 100 0%, 0 0%). Beachten

Wie erstelle ich reaktionsschnelle Bilder mit CSS? Wie erstelle ich reaktionsschnelle Bilder mit CSS? Jul 15, 2025 am 01:10 AM

Um reaktionsschnelle Bilder mit CSS zu erstellen, kann es haupts?chlich durch die folgenden Methoden erreicht werden: 1. Verwenden Sie maximale Breite: 100% und H?he: Auto, damit das Bild an die Containerbreite anpasst und gleichzeitig den Anteil beibeh?lt. 2. Verwenden Sie die SRCSet- und Gr??enattribute von HTML, um die an verschiedenen Bildschirme angepassten Bildquellen intelligent zu laden. 3.. Verwenden Sie Objektfit und Objektposition, um die Bildaufbindung und Fokusanzeige zu steuern. Gemeinsam stellen diese Methoden sicher, dass die Bilder auf verschiedenen Ger?ten klar und wundersch?n pr?sentiert werden.

Was sind gemeinsame Inkonsistenzen von CSS -Browser? Was sind gemeinsame Inkonsistenzen von CSS -Browser? Jul 26, 2025 am 07:04 AM

Verschiedene Browser weisen Unterschiede in der CSS -Analyse auf, was zu inkonsistenten Anzeigeeffekten führt, haupts?chlich die Differenzentscheidung, die Berechnung des Boxmodells, die Flexbox- und Raster -Layout -Unterstützung und das inkonsistente Verhalten bestimmter CSS -Attribute. 1. Die Standardstilverarbeitung ist inkonsistent. Die L?sung besteht darin, CSSReset oder Normalize.css zu verwenden, um den anf?nglichen Stil zu vereinen. 2. Die Box -Modellberechnung der alten Version von IE ist unterschiedlich. Es wird empfohlen, eine einheitliche Boxgr??e: Border-Box zu verwenden. 3. Flexbox und Grid führen in Kantenf?llen oder in alten Versionen unterschiedlich ab. Weitere Tests und verwenden Sie Autoprefixer; 4. Einige CSS -Attributverhalten sind inkonsistent. Caniuse muss konsultiert und herabgestuft werden.

Entmystifizierende CSS -Einheiten: PX, EM, REM, VW, VH -Vergleiche Entmystifizierende CSS -Einheiten: PX, EM, REM, VW, VH -Vergleiche Jul 08, 2025 am 02:16 AM

Die Auswahl der CSS -Einheiten h?ngt von den Entwurfsanforderungen und den reaktionsschnellen Anforderungen ab. 1.PX wird für die feste Gr??e verwendet, geeignet für eine pr?zise Kontrolle, aber mangelnde Elastizit?t; 2.Em ist eine relative Einheit, die leicht durch den Einfluss des übergeordneten Elements verursacht wird, w?hrend REM basierend auf dem Wurzelelement stabiler ist und für die globale Skalierung geeignet ist. 3.VW/VH basiert auf der Ansichtsfenstergr??e, die für das reaktionsschnelle Design geeignet ist. Die Leistung unter extremen Bildschirmen sollte jedoch Aufmerksamkeit geschenkt werden. 4. Bei der Auswahl sollte es ermittelt werden, ob reaktionsschnelle Anpassungen, Elementhierarchiebeziehungen und Ansichtsfensterabh?ngigkeit festgelegt werden. Angemessener Gebrauch kann die Layoutflexibilit?t und -wartung verbessern.

Beschreiben Sie das Eigentum 'Opazit?t' Beschreiben Sie das Eigentum 'Opazit?t' Jul 15, 2025 am 01:23 AM

Opazit?t ist ein Attribut in CSS, das die Gesamttransparenz eines Elements steuert, wobei die Werte von 0 (vollst?ndig transparent) bis 1 (vollst?ndig undurchsichtig) reichen. 1. Es wird h?ufig für den Image -Schwebeverlusteffekt verwendet und verbessert die interaktive Erfahrung, indem der übergang der Deckkraft festgelegt wird. 2.. Erstellen einer Hintergrundmaskenschicht, um die Textlesbarkeit zu verbessern; 3.. Visuelle Feedback von Steuertasten oder Symbolen im behinderten Zustand. Beachten Sie, dass es im Gegensatz zu RGBA, was nur den angegebenen Farbteil betrifft, alle Kinderelemente betrifft. Eine reibungslose Animation kann durch den übergang erreicht werden, aber h?ufiger Gebrauch kann die Leistung beeinflussen. Es wird empfohlen, es in Kombination mit dem Willenswechsel oder der Transformation zu verwenden. Die rationale Anwendung der Opazit?t kann die Seitenhierarchie und die Interaktivit?t verbessern, sollte jedoch vermeiden, dass sie die Benutzer beeintr?chtigen.

Was ist die Akzentfarbe? Was ist die Akzentfarbe? Jul 26, 2025 am 09:25 AM

Accent-Color ist ein Attribut, das in CSS verwendet wird, um die Highlight-Farben von Formularelementen wie Kontrollk?stchen, Optionsfeldern und Schieberegler anzupassen. 1. Es ?ndert direkt die Standardfarbe des ausgew?hlten Status des Formularsteuerers, z. 2. Die unterstützten Elemente umfassen Eingangsk?stchen von Typ = "Kontrollk?stchen", type = "radio" und type = "range"; 3. Die Verwendung von Akzentfarben kann komplexe benutzerdefinierte Stile und zus?tzliche DOM-Strukturen vermeiden und die native Zug?nglichkeit aufrechterhalten. 4. Es wird im Allgemeinen von modernen Browsern unterstützt, und alte Browser müssen herabgestuft werden. 5. Setzen Sie Accent-Col

See all articles