标签:watch async toe http ast new bsp turn json
测试对于框架来说比较重要,对于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"
},
主要函数
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
标签:watch async toe http ast new bsp turn json
原文地址:https://www.cnblogs.com/rongfengliang/p/9711224.html