Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useCssVar): introduce
observe
option (#2800)
- Loading branch information
1 parent
9194d59
commit ae6e174
Showing
2 changed files
with
58 additions
and
8 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,32 @@ | ||
import { defaultWindow } from '@vueuse/core' | ||
import { nextTick } from 'vue-demi' | ||
import { useCssVar } from '.' | ||
|
||
describe('useCssVar', () => { | ||
it('should be defined', () => { | ||
expect(useCssVar).toBeDefined() | ||
}) | ||
|
||
it('should work', () => { | ||
const el = document.createElement('div') | ||
const color = '--color' | ||
const variable = useCssVar(color, el, { initialValue: 'red' }) | ||
|
||
expect(variable.value).toBe('red') | ||
}) | ||
|
||
it('should work observe', async () => { | ||
const window = defaultWindow | ||
const el = document.createElement('div') | ||
window?.document.body.appendChild(el) | ||
|
||
const color = '--color' | ||
const variable = useCssVar(color, el, { initialValue: 'red', observe: true }) | ||
|
||
expect(variable.value).toBe('red') | ||
|
||
el.style.setProperty(color, 'blue') | ||
await nextTick() | ||
expect(variable.value).toBe('blue') | ||
}) | ||
}) |
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