Skip to content

Commit

Permalink
test: ResizeObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 21, 2024
1 parent 19bc13b commit 8fadc87
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.22.0",
"jsdom": "^24.1.0",
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.71.1",
"string-hash": "^1.1.3",
"vite": "^5.1.5",
Expand Down
23 changes: 11 additions & 12 deletions src/packages/resize-observer/__tests__/ResizeObserver.test.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import ResizeObserver from '../index'
import mountTest from '../../../../tests/shared/mountTest'
import MockResizeObserver from '../../../../tests/__mocks__/resize-observer'

describe('ResizeObserver', () => {
it(`render`, async () => {
const wrapper = mount(ResizeObserver, {
slots: {
default: () => {
return (
<div style={{ height: '200px' }}/>
)
}
}
})
expect(wrapper.exists()).toBeTruthy()
beforeEach(() => {
window.ResizeObserver = MockResizeObserver
})

mountTest(ResizeObserver)
it(`emits resize`, async () => {
const wrapper = mount(ResizeObserver)
expect(wrapper.emitted()).toHaveProperty('resize')
})
})
19 changes: 19 additions & 0 deletions tests/__mocks__/resize-observer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class ResizeObserver {
constructor (callback) {
const entry = {
contentRect: { width: 1024, height: 768 }
}
callback([entry])
}

observe () {
}

unobserve () {
}

disconnect () {
}
}

export default ResizeObserver
2 changes: 0 additions & 2 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { vi } from 'vitest'
import { config } from '@vue/test-utils'
import ResizeObserverPolyfill from 'resize-observer-polyfill'
import { TextDecoder, TextEncoder } from 'node:util'

// config
Expand Down Expand Up @@ -53,7 +52,6 @@ window.getComputedStyle = (ele) => {
}

// Mock requestAnimationFrame
global.ResizeObserver = ResizeObserverPolyfill
global.requestAnimationFrame = (callback) => {
return setTimeout(callback, 0)
}
Expand Down

0 comments on commit 8fadc87

Please sign in to comment.