-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`image :base 1`] = ` | ||
<main> | ||
<t-image> | ||
<wx-view | ||
class="t-class t-image t-image__mask t-image--faild t-image--shape-square" | ||
> | ||
<wx-view | ||
class="t-class-load" | ||
style="font-size: 40rpx; color: #999" | ||
> | ||
<t-icon> | ||
<wx-label | ||
class="t-class t-icon t-icon-close t-icon-base" | ||
style=";;" | ||
bind:tap="onTap" | ||
/> | ||
</t-icon> | ||
</wx-view> | ||
</wx-view> | ||
<wx-image | ||
class="t-class t-image t-image--shape-square" | ||
hidden="{{true}}" | ||
id="image" | ||
lazyLoad="{{false}}" | ||
mode="scaleToFill" | ||
showMenuByLongpress="{{false}}" | ||
src="" | ||
style="" | ||
webp="{{false}}" | ||
bind:error="onLoadError" | ||
bind:load="onLoaded" | ||
/> | ||
</t-image> | ||
</main> | ||
`; | ||
|
||
exports[`image :success 1`] = ` | ||
<main> | ||
<t-image | ||
id="root" | ||
bind:load="handleLoad" | ||
> | ||
<wx-image | ||
class="t-class t-image t-image--shape-square" | ||
hidden="{{false}}" | ||
id="image" | ||
lazyLoad="{{false}}" | ||
mode="heightFix" | ||
showMenuByLongpress="{{false}}" | ||
src="https://www.tencent.com/img/index/menu_logo.png" | ||
style="width: 0.00px;" | ||
webp="{{false}}" | ||
bind:error="onLoadError" | ||
bind:load="onLoaded" | ||
/> | ||
</t-image> | ||
</main> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import simulate from 'miniprogram-simulate'; | ||
import path from 'path'; | ||
|
||
describe('image', () => { | ||
const image = simulate.load(path.resolve(__dirname, `../image`), 't-image', { | ||
less: true, | ||
rootPath: path.resolve(__dirname, '../..'), | ||
}); | ||
|
||
it(':base', () => { | ||
const id = simulate.load({ | ||
template: `<t-image></t-image>`, | ||
usingComponents: { | ||
't-image': image, | ||
}, | ||
}); | ||
const comp = simulate.render(id); | ||
comp.attach(document.createElement('parent-wrapper')); | ||
|
||
expect(comp.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it(':success', async () => { | ||
const handleLoad = jest.fn(); | ||
const id = simulate.load({ | ||
template: `<t-image | ||
id="root" | ||
mode="{{mode}}" | ||
src="https://www.tencent.com/img/index/menu_logo.png" | ||
bind:load="handleLoad" | ||
/>`, | ||
data: { | ||
mode: 'widthFix', | ||
}, | ||
methods: { | ||
handleLoad, | ||
}, | ||
usingComponents: { | ||
't-image': image, | ||
}, | ||
}); | ||
const comp = simulate.render(id); | ||
comp.attach(document.createElement('parent-wrapper')); | ||
|
||
const $image = comp.querySelector('#root >>> #image'); | ||
|
||
$image.dispatchEvent('load', { detail: { width: 100, height: 100 } }); | ||
|
||
await simulate.sleep(); | ||
|
||
expect(handleLoad).toHaveBeenCalled(); | ||
|
||
// height fixed | ||
const mock = jest.spyOn(wx, 'getSystemInfoSync'); | ||
mock.mockImplementation(() => ({ SDKVersion: '2.10.2' })); | ||
|
||
comp.setData({ mode: 'heightFix' }); | ||
$image.dispatchEvent('load', { detail: { width: 100, height: 100 } }); | ||
|
||
await simulate.sleep(); | ||
expect(comp.toJSON()).toMatchSnapshot(); | ||
|
||
mock.mockRestore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters