测试对于框架来说比较重要,对于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. 在 Confluence 6 中连 Jira 的问题解决

    下面是可能会发生的一些错误信息.如果你的系统中出现了下面的一些提示,你应该调整你的日志错误级别到 WARN,然后查看具体的错误原因.请参考:Configuring Logging. error.jir ...

  2. python-day4笔记

    1.文件后缀名对python运行没关系 2.Python解释器执行python程序的过程:python3 C:\test.py 1)启动python解释器(内存中) 2)将C:\test.py内容从硬 ...

  3. 对象不能从 DBNull 转换为其他类型

    SQL语句:select sum (datediff(second,Begin_Time,End_Time)) as 总时长 from 数据表这是我开始的程序:int 总时长=0;总时长 =Conve ...

  4. Error: Chunk.entry was removed. Use hasRuntime()错误解决

      Error: Chunk.entry was removed. Use hasRuntime()错误解决           执行如下命令 npm uninstall --save-dev ext ...

  5. Dos命令的介绍

    Dos命令的介绍目录 1.什么是Dos 2.Dos的简介 3.Dos命令有哪些 4.Dos命令下常见的错误信息 5.Config.sys文件的命令和配置 6.Dos自带的的批处理命令 1.什么是Dos ...

  6. cas 服务端相关配置

    SSO-安全证书配置 CAS默认使用的是HTTPS协议,如果对安全要求不高,可以使用HTTP协议 修改deployerConfigContext.xml(cas/WEB-INF)增加参数 p:requ ...

  7. SQL Server 自动化运维系列 - 多服务器数据收集和性能监控

    需求描述 在生产环境中,很多情况下需要采集数据,用以定位问题或者形成基线. 关于SQL Server中的数据采集有着很多种的解决思路,可以采用Trace.Profile.SQLdiag.扩展事件等诸多 ...

  8. AngularJS-----$compile

    原文:http://docs.ngnice.com/api/ng/service/$compile 写在前面的话: 之前我一直理解错误,我一直以为这句--function([scope], clone ...

  9. SQL2012 创建备份计划

    打开数据库,选择 管理 -> 新建维护计划,填写计划名称 修改计划参数 工具箱->备份数据库任务,拖到计划里 编辑任务 拖动清除数据库任务到计划 编辑清除任务 从备份任务到清除任务拖一个箭 ...

  10. get_class

    <?phpclass foo {    function foo()    {    // implements some logic    }    function name()    {  ...