stenciljs 学习八 组件测试
测试对于框架来说比较重要,对于web 组件的测试同样很重要,类似的jest 很方便,stenciljs也是基于jest 开发的
包含两个核心api render(), flush()
测试配置
package.json 配置
"devDependencies": {
...
"@types/jest": "^21.1.1",
"jest": "^21.2.1"
},
npm script 配置
"scripts": {
...
"test": "jest --no-cache",
"test.watch": "jest --watch --no-cache"
},
组件渲染测试
主要函数
- render({components:[],html:string} ) 进行组件列表的渲染,html 是html 的代码片段,包含组件的使用
- flush(element) 用来在属性变更之后刷新元素
渲染组件
- components 组件列表
- html html 片段
参考
beforeEach(async () => {
element = await render({
components: [MyName],
html: '<my-name></my-name>'
});
});
刷新组件
flush 函数
it('should work with both the first and the last name', async () => {
element.first = 'Peter'
element.last = 'Parker';
await flush(element);
expect(element.textContent).toEqual('Hello, my name is Peter Parker');
});
组件测试
参考
it('should least each part of the name breaking on spaces', async () => {
element.first = 'Pasta Primavera';
element.last = 'O Shea Buttersworth';
await flush(element);
const list = element.querySelector('ul');
expect(list.children.length).toEqual(5);
expect(list.children[0].textContent).toEqual('Pasta');
expect(list.children[1].textContent).toEqual('Primavera');
expect(list.children[2].textContent).toEqual('O');
expect(list.children[3].textContent).toEqual('Shea');
expect(list.children[4].textContent).toEqual('Buttersworth');
});
组件方法测试
it('should return an empty string if there is no first or last name', () => {
const myName = new MyName();
expect(myName.formatted()).toEqual('');
});
参考资料
https://stenciljs.com/docs/unit-testing
stenciljs 学习八 组件测试的更多相关文章
- stenciljs 学习六 组件开发样式指南
组件不是动作,最好使用名词而不是动词, 文件结构 每个文件一个组件. 每个目录一个组件.虽然将类似的组件分组到同一目录中可能是有意义的,但我们发现当每个组件都有自己的目录时,更容易记录组件. 实现(. ...
- stenciljs 学习四 组件装饰器
stenciljs 可以方便的构建交互式组件 支持以下装饰器 component prop watch state method element component 说明 component 包含ta ...
- stenciljs 学习三 组件生命周期
stenciljs 组件包含好多生命周期方法, will did load update unload 实现生命周期的方法比价简单类似 componentWillLoad ....,使用typescr ...
- Android Testing学习01 介绍 测试测什么 测试的类型
Android Testing学习01 介绍 测试测什么 测试的类型 Android 测试 测什么 1.Activity的生命周期事件 应该测试Activity的生命周期事件处理. 如果你的Activ ...
- Python Tutorial 学习(八)--Errors and Exceptions
Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...
- surging如何使用swagger 组件测试业务模块
1.前言 微服务架构概念的提出已经有非常长一段时间了,但在近期几年却开始频繁地出现,大家都着手升级成微服务架构,使用着各种技术,大家认为框架有服务治理就是微服务,实现单一协议的服务调用,微服务虽然没有 ...
- Shell学习之条件测试(四)
Shell学习之条件测试 目录 逻辑测试 文件测试 数值比较 字符串比较 逻辑测试 格式: [ 表达式 ] 操作符 [ 表达式2 ] …… 命令1 操作符 命令2 …… 常用的操作符 ( 注意:-a和 ...
- SVG 学习<八> SVG的路径——path(2)贝塞尔曲线命令、光滑贝塞尔曲线命令
目录 SVG 学习<一>基础图形及线段 SVG 学习<二>进阶 SVG世界,视野,视窗 stroke属性 svg分组 SVG 学习<三>渐变 SVG 学习<四 ...
- Hadoop YARN学习之组件功能简述(3)
Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...
随机推荐
- 1月24日 ruby基础3部分 Numeric, Array已学。
<div style="background:lightblue"> 第12章 数值类 12.1 数值的构成 Numeric-> Integer-> Fix ...
- 54 Django 模型层(1) 单表查询
单表操作: 一 项目的操作顺序: 1 在model.py文件中创建表结构 class Book(models.Model): id=models.AutoField(primary_key=True) ...
- FasfDFS intall nginx with image filter
centOS7 x64 1. install gd-devel 2. ./configure --prefix=/usr/local/nginx --with-http_image_filter_mo ...
- Leetcode 526
class Solution { public: int countArrangement(int N) { vector<int> nums; ;i <= N;i++) nums. ...
- HDOJ1004
#include<iostream> #include "cstring" using namespace std; int add(char s1[],char s2 ...
- java连接MySql数据库 zeroDateTimeBehavior
JAVA连接MySQL数据库,在操作值为0的timestamp类型时不能正确的处理,而是默认抛出一个异常, 就是所见的:java.sql.SQLException: Cannot convert va ...
- c中gets函数使用可能导致缓冲区溢出
头文件:#include <stdio.h> gets()函数用于从缓冲区中读取字符串,其原型如下: char *gets(char *string); gets()函数从流中读取字 ...
- 对spring 对持久层的支持和数据库连接池的理解
1.spring对持久层的支持在于,得到数据库连接之后操作上的封装,将操作简化了.也就是说以后操作sql语句就用XXXTemplate(就是一个工具类)对象了. 2.数据库连接池的作用只在于得到数据库 ...
- 一张图告诉你为何必须学Python?
互联网行业的薪资高.发展前景好,已经是人尽皆知的事了.越来越多的人对编程有了兴趣,想通过加入大公司实现人生逆袭,我们身边也涌现出了一些从零学习.变身大神的励志故事. 但更多的人还是选择观望:有人觉得编 ...
- Linux 查看服务器硬件信息
目录 CPU CPU 总核数 = 物理CPU个数 X 每颗物理CPU的核数 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 查看路数/Socket(s) cat /proc ...