Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
Not only does the Open Web Components project provide the generator that we are basing our web component on in this conversation, but they also vend Chai A11y aXe which binds axe-core with Chai assertions for easy consumption in the @web/test-runner environment. This means that you can use the industry standard accessibility testing engine to confirm the accessibility of your web component at unit test time. This looks like the following:
npm init @open-wc@latest Need to install the following packages: @open-wc/[email protected] Ok to proceed? (y) y _.,,,,,,,,,._ .d'' ``b. Open Web Components Recommendations .p' Open `q. .d' Web Components `b. Start or upgrade your web component project with .d' `b. ease. All our recommendations at your fingertips. :: ................. :: `p. .q' `p. open-wc.org .q' `b. @openWc .d' `q.. ..,' See more details at https://open-wc.org/init/ '',,,,,,,,,,'' Note: you can exit any time with Ctrl+C or Esc ✔ What would you like to do today? › Scaffold a new project ✔ What would you like to scaffold? › Web Component ✔ What would you like to add? › Testing (web-test-runner) ✔ Would you like to use typescript? › Yes ✔ What is the tag name of your web component? … testing-components ./ ├── testing-components/ │ ├── .vscode/ │ │ └── extensions.json │ ├── demo/ │ │ └── index.html │ ├── src/ │ │ ├── index.ts │ │ ├── testing-components.ts │ │ └── TestingComponents.ts │ ├── test/ │ │ └── testing-components.test.ts │ ├── .editorconfig │ ├── .gitignore │ ├── LICENSE │ ├── package.json │ ├── README.md │ ├── tsconfig.json │ ├── web-dev-server.config.mjs │ └── web-test-runner.config.mjs ✔ Do you want to write this file structure to disk? › Yes Writing..... done ✔ Do you want to install dependencies? › Yes, with npm
So, you write web components and you're interested in expanding the work you put into unit testing them? Well, you've come to the right place. This is just the beginning, but Testing Web Components: the Series is going to lay out for you how Open Web Components and Modern Web help you to do just that. We'll start with how the Open Web Components generator can get you up and running in no time with @web/test/runner right out of the box.
npm test > [email protected] test > tsc && wtr --coverage dist/test/testing-components.test.js: 🚧 Browser logs: Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information. Chrome: |██████████████████████████████| 1/1 test files | 4 passed, 0 failed Code coverage: 100 % View full coverage report at coverage/lcov-report/index.html Finished running tests in 9s, all tests passed! 🎉