测试对于框架来说比较重要,对于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 学习八 组件测试的更多相关文章

  1. stenciljs 学习六 组件开发样式指南

    组件不是动作,最好使用名词而不是动词, 文件结构 每个文件一个组件. 每个目录一个组件.虽然将类似的组件分组到同一目录中可能是有意义的,但我们发现当每个组件都有自己的目录时,更容易记录组件. 实现(. ...

  2. stenciljs 学习四 组件装饰器

    stenciljs 可以方便的构建交互式组件 支持以下装饰器 component prop watch state method element component 说明 component 包含ta ...

  3. stenciljs 学习三 组件生命周期

    stenciljs 组件包含好多生命周期方法, will did load update unload 实现生命周期的方法比价简单类似 componentWillLoad ....,使用typescr ...

  4. Android Testing学习01 介绍 测试测什么 测试的类型

    Android Testing学习01 介绍 测试测什么 测试的类型 Android 测试 测什么 1.Activity的生命周期事件 应该测试Activity的生命周期事件处理. 如果你的Activ ...

  5. Python Tutorial 学习(八)--Errors and Exceptions

    Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...

  6. surging如何使用swagger 组件测试业务模块

    1.前言 微服务架构概念的提出已经有非常长一段时间了,但在近期几年却开始频繁地出现,大家都着手升级成微服务架构,使用着各种技术,大家认为框架有服务治理就是微服务,实现单一协议的服务调用,微服务虽然没有 ...

  7. Shell学习之条件测试(四)

    Shell学习之条件测试 目录 逻辑测试 文件测试 数值比较 字符串比较 逻辑测试 格式: [ 表达式 ] 操作符 [ 表达式2 ] …… 命令1 操作符 命令2 …… 常用的操作符 ( 注意:-a和 ...

  8. SVG 学习<八> SVG的路径——path(2)贝塞尔曲线命令、光滑贝塞尔曲线命令

    目录 SVG 学习<一>基础图形及线段 SVG 学习<二>进阶 SVG世界,视野,视窗 stroke属性 svg分组 SVG 学习<三>渐变 SVG 学习<四 ...

  9. Hadoop YARN学习之组件功能简述(3)

    Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...

随机推荐

  1. android--------阿里 Sophix移动热修复

    移动热修复(Mobile Hotfix)是阿里云提供的全平台App热修复服务方案.产品基于阿里巴巴首创hotpatch技术,提供最细粒度热修复能力,让您无需等待实时修复应用线上问题. 移动热修复提供的 ...

  2. bzoj3944: Sum 杜教筛板子题

    板子题(卡常) 也可能是用map太慢了 /************************************************************** Problem: 3944 Us ...

  3. OAF中多语言的实现(转)

    正好前两天研究过这个问题,分享一下啊. 标题:        OAF中多语言的实现概述:        OAF的多语言的实现有两种方式,其一是直接通过页面上面的“个性化”连接,连接到指定的页面后,进行 ...

  4. idea Exception in thread "http-apr-8080-exec-2" java.lang.OutOfMemoryError: PermGen space

    idea Exception in thread "http-apr-8080-exec-2" java.lang.OutOfMemoryError: PermGen space ...

  5. learning uboot enable protect console

    reference :https://github.com/lentinj/u-boot/blob/master/doc/README.autoboot how to enable protect s ...

  6. React教程-初入

    学习了React很久,一直没有机会总结下,最近打算写一个简单的React,希望让初学者一看就懂,不走弯路,我尽量写的简明点好了开始吧!首页我们要利用npm安装 react(当然你也可以用引用方式)跟着 ...

  7. sgu107. 987654321 problem 简单打表 难度:0

    107. 987654321 problem time limit per test: 0.25 sec. memory limit per test: 4096 KB For given numbe ...

  8. golang模拟动态高优先权优先调度算法

    实验二  动态高优先权优先调度 实验内容 模拟实现动态高优先权优先(若数值越大优先权越高,每运行一个时间单位优先权-n,若数值越小优先权越高,没运行一个时间单位优先权+n),具体如下: 设置进程体:进 ...

  9. Delphi中的文件扩展名

    Filename Extensions in Delphi http://delphi.about.com/od/beginners/a/aa032800a.htm Try building a sm ...

  10. 【笔记】《深入浅出MFC》第6章 MFC程序的生死因果

    一.头文件说明 STDAFX.H 这个文件用来作为Precompile header file,其内只是载入其他的MFC头文件.应用程序通常会准备自己的头STDAFX.H. AFXWIN.H 每一个W ...