diff --git a/src/fab/README.md b/src/fab/README.md index 679933664..0ba9127ce 100644 --- a/src/fab/README.md +++ b/src/fab/README.md @@ -5,6 +5,7 @@ spline: form isComponent: true --- + ## 引入 全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。 diff --git a/src/fab/__test__/index.test.js b/src/fab/__test__/index.test.js new file mode 100644 index 000000000..80bb1c8a1 --- /dev/null +++ b/src/fab/__test__/index.test.js @@ -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: ``, + 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: ``, + 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(); + }); +});