Skip to content

Commit

Permalink
Merge pull request #740 from Tencent/test/fab/unit
Browse files Browse the repository at this point in the history
test(fab): add unit test
  • Loading branch information
LeeJim authored Aug 9, 2022
2 parents 7623b5b + 712534d commit 106380b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ spline: form
isComponent: true
---

<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-100%25-blue" /></span>
## 引入

全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
Expand Down
50 changes: 50 additions & 0 deletions src/fab/__test__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import simulate from 'miniprogram-simulate';
import path from 'path';

describe('fab', () => {
const fab = simulate.load(path.resolve(__dirname, `../fab`), 't-fab', {
less: true,
rootPath: path.resolve(__dirname, '../../'),
});
it(`fab :base`, async () => {
const id = simulate.load({
template: `<t-fab class="fab" text="{{text}}"></fab>`,
usingComponents: {
't-fab': fab,
},
data: {
text: 'base',
},
});
const comp = simulate.render(id);
comp.attach(document.createElement('parent-wrapper'));

const $content = comp.querySelector('.fab >>> .t-button__content');

expect($content.dom.textContent).toBe('base');

comp.setData({ text: '' });

expect($content.dom.textContent).toBe('');
});

it(`fab :event`, async () => {
const fn = jest.fn();
const id = simulate.load({
template: `<t-fab class="fab" bind:click="handleClick"></fab>`,
methods: {
handleClick: fn,
},
usingComponents: {
't-fab': fab,
},
});
const comp = simulate.render(id);
comp.attach(document.createElement('parent-wrapper'));

comp.querySelector('.fab >>> .t-button').dispatchEvent('tap');
await simulate.sleep(10);

expect(fn).toHaveBeenCalled();
});
});

0 comments on commit 106380b

Please sign in to comment.