Skip to content

Commit

Permalink
fix(test): 单测更新
Browse files Browse the repository at this point in the history
  • Loading branch information
QiuShuiBai committed Mar 14, 2024
1 parent 7ef0b3a commit 9f4edb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('component picker unit test', function () {
'cube-date-picker-modal': componentId
},
template: `
<cube-date-picker-modal value="{{${+new Date('2023-02-10')}}}">
<cube-date-picker-modal value="{{${+new Date('2023-02-10')}}}" max="{{${+new Date('2024/12/31 23:59:59')}}}">
<view class="header-slot" slot="header">${headerMessage}</view>
<view class="footer-slot" slot="footer">${footerMessage}</view>
</cube-date-picker-modal>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`component toast unit test base props check matchSnapshot 1`] = `"<cube-popup class=\\"main--ref_popup_1 main--cube-toast\\"><wx-view class=\\"cube-popup--cube-popup cube-popup--cube-popup_mask cube-popup--cube-popup_transition cube-popup--cube-popup-center\\" style=\\"z-index: 900\\"><wx-view class=\\"cube-popup--cube-popup-mask\\"></wx-view><wx-view class=\\"cube-popup--cube-popup-content cube-popup--fade\\"><wx-view class=\\"main--toast-slot-icon\\"></wx-view><cube-icon class=\\"main--cube-toast-icon\\"><wx-view class=\\"cube-icon--cubeic cube-icon--cubeic cube-icon--cubeic-delete\\" style=\\"\\"></wx-view></cube-icon><wx-view class=\\"main--cube-toast-tip\\">hello toast</wx-view></wx-view></wx-view></cube-popup>"`;
exports[`component toast unit test base props check matchSnapshot 1`] = `"<cube-popup class=\\"main--ref_popup_1 main--cube-toast\\"><wx-view class=\\"cube-popup--cube-popup cube-popup--cube-popup_mask cube-popup--cube-popup_transition cube-popup--cube-popup-center cube-popup--show\\" style=\\"z-index: 900\\"><wx-view class=\\"cube-popup--cube-popup-mask\\"></wx-view><wx-view class=\\"cube-popup--cube-popup-content cube-popup--fade\\"><wx-view class=\\"main--toast-slot-icon\\"></wx-view><cube-icon class=\\"main--cube-toast-icon\\"><wx-view class=\\"cube-icon--cubeic cube-icon--cubeic cube-icon--cubeic-delete\\" style=\\"\\"></wx-view></cube-icon><wx-view class=\\"main--cube-toast-tip\\">hello toast</wx-view></wx-view></wx-view></cube-popup>"`;
exports[`component toast unit test event check matchSnapshot 1`] = `"<cube-popup class=\\"main--ref_popup_1 main--cube-toast\\"><wx-view class=\\"cube-popup--cube-popup cube-popup--cube-popup_mask cube-popup--cube-popup_transition cube-popup--cube-popup-center cube-popup--show\\" style=\\"z-index: 900\\"><wx-view class=\\"cube-popup--cube-popup-mask\\"></wx-view><wx-view class=\\"cube-popup--cube-popup-content cube-popup--fade\\"><wx-view class=\\"main--toast-slot-icon\\"></wx-view><cube-icon class=\\"main--cube-toast-icon\\"><wx-view class=\\"cube-icon--cubeic cube-icon--cubeic cube-icon--cubeic-delete\\" style=\\"\\"></wx-view></cube-icon><wx-view class=\\"main--cube-toast-tip\\">hello toast</wx-view></wx-view></wx-view></cube-popup>"`;
exports[`component toast unit test slot check matchSnapshot 1`] = `"<main><cube-popup class=\\"main--ref_popup_1 main--cube-toast\\"><wx-view class=\\"cube-popup--cube-popup cube-popup--cube-popup_transition cube-popup--cube-popup-center\\" style=\\"z-index: 900\\"><wx-view class=\\"cube-popup--cube-popup-mask\\"></wx-view><wx-view class=\\"cube-popup--cube-popup-content cube-popup--fade\\"><wx-view class=\\"main--toast-slot-icon\\"><wx-image class=\\"custom-img\\"><wx-view class=\\"my-image\\">https://dpubstatic.udache.com/static/dpubimg/c40384a2-25ef-4781-8e08-44447823d861.png</wx-view></wx-image></wx-view><wx-view class=\\"main--cube-toast-tip\\">请输入乘车人手机号</wx-view></wx-view></wx-view></cube-popup></main>"`;
exports[`component toast unit test slot check matchSnapshot 1`] = `"<main><cube-popup class=\\"main--ref_popup_1 main--cube-toast\\"><wx-view class=\\"cube-popup--cube-popup cube-popup--cube-popup_transition cube-popup--cube-popup-center cube-popup--show\\" style=\\"z-index: 900\\"><wx-view class=\\"cube-popup--cube-popup-mask\\"></wx-view><wx-view class=\\"cube-popup--cube-popup-content cube-popup--fade\\"><wx-view class=\\"main--toast-slot-icon\\"><wx-image class=\\"custom-img\\"><wx-view class=\\"my-image\\">https://dpubstatic.udache.com/static/dpubimg/c40384a2-25ef-4781-8e08-44447823d861.png</wx-view></wx-image></wx-view><wx-view class=\\"main--cube-toast-tip\\">请输入乘车人手机号</wx-view></wx-view></wx-view></cube-popup></main>"`;
14 changes: 8 additions & 6 deletions packages/mpx-cube-ui/__tests__/components/toast/toast.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('component toast unit test', function() {
icon: 'delete' // 图标类型(自动添加cubeic-前缀)
}
describe('base props check', () => {
const component = newComponent(baseProps)
const component = newComponent(Object.assign({ visible: true }, baseProps))
component.instance.show()
it('matchSnapshot', () => {
expect(component.dom.innerHTML).toMatchSnapshot() // 判断前后生成的dom是否一样
})
Expand All @@ -36,17 +37,17 @@ describe('component toast unit test', function() {
it('should be visibled through the "show" method', async () => {
// 不能通过一个 querySelector 来选取,查看 https://github.com/wechat-miniprogram/miniprogram-simulate/issues/53
component.instance.show()
await simulate.sleep(10)
await simulate.sleep(5)
const showDom = component.querySelector('.cube-toast').querySelector('.show') // props.visible 正确
expect(showDom).toBeTruthy()

expect(component.instance.data.isVisible).toBe(true)
})
it('should be invisibled through the "hide" method', async () => {
component.instance.hide()
await simulate.sleep(10)
const showDom = component.querySelector('.cube-toast').querySelector('.hide') // props.visible 正确
expect(showDom).toBeTruthy()
await simulate.sleep(5)
const dom = component.querySelector('.cube-toast')
expect(dom).toBe(undefined)

expect(component.instance.data.isVisible).toBe(false)
})
Expand All @@ -65,7 +66,7 @@ describe('component toast unit test', function() {
expect(component.instance.data.isVisible).toBe(true)
const mask = component.querySelector('.cube-toast').querySelector('.cube-popup-mask')
mask.dispatchEvent('touchend')
await simulate.sleep(10)
await simulate.sleep(5)

expect(component.instance.data.isVisible).toBe(false)
expect(onToggleFn).toHaveBeenCalled()
Expand All @@ -80,6 +81,7 @@ describe('component toast unit test', function() {
template: `
<cube-toast
txt="请输入乘车人手机号"
visible="{{ ${true} }}"
wx:ref="toastImg">
${imageSlot}
</cube-toast>
Expand Down

0 comments on commit 9f4edb2

Please sign in to comment.