テスト
In order to ensure that your Stencil components work the way you expect, Stencil provides testing support out of the box. Stencil offers both unit testing and end-to-end testing capabilities.
ユニットテストとエンドツーエンドテスト
Testing within Stencil is broken up into two distinct types: Unit tests and End-to-end (e2e) tests.
There are several philosophies on how testing should be done, and how to differentiate what should be considered a unit test versus an end-to-end test. Stencil takes an opinionated stance so developers have a description of each to better choose when to use each type of testing:
Unit tests focus on testing a component's methods in isolation. For example, when a method is given the argument
X, it should return Y.
End-to-end tests focus on how the components are rendered in the DOM and how the individual components work
together. For example, when my-component has the X attribute, the child component then renders the text Y, and
expects to receive the event Z.
Both types of testing use Jest as the JavaScript testing solution. End-to-end tests also use Puppeteer instead of a Node environment. This allows end-to-end tests to run within an actual browser in order to provide more realistic results.
Library Support
Stencil uses Jest and Puppeteer as its testing libraries, and allows developers to install both libraries using their preferred package manager.
If you created a project using npm init stencil, these libraries were installed for you. Depending on when your
project was created, you may or may not have the latest supported version installed.
To view current version support for both Jest and Puppeteer, please see the Stencil support policy for testing libraries.