Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/taro-h5/__tests__/wxml/mediaQueryObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ describe.each(['modern', 'legacy'])('MediaQueryObserver with %s listeners', mode
else Reflect.deleteProperty(window, 'matchMedia')
})

test.each(['width', 'minWidth', 'maxWidth', 'height', 'minHeight', 'maxHeight'])('retains an explicit zero for %s', key => {
observer.observe({ [key]: 0 }, jest.fn())
const cssName = key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase())
expect(window.matchMedia).toHaveBeenCalledWith(`(${cssName}: 0px)`)
})

test('reports the initial state and changes until disconnected', () => {
const callback = jest.fn()
observer.observe(narrow, callback)
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-h5/src/api/wxml/MediaQueryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function generateMediaQueryStr (descriptor: Taro.MediaQueryObserver.descriptor)
for (const item of descriptorMenu) {
if (
item !== 'orientation' &&
descriptor[item] &&
(descriptor[item] || descriptor[item] === 0) &&
Number(descriptor[item]) >= 0
) {
mediaQueryArr.push(`(${(toKebabCase(item))}: ${Number(descriptor[item])}px)`)
Expand Down
Loading