Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(useFavicon): improve type overload (#2123)
- Loading branch information
Showing
2 changed files
with
73 additions
and
4 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,69 @@ | ||
import { describe, expect } from 'vitest' | ||
import { computed, ref } from 'vue' | ||
import { useFavicon } from '.' | ||
|
||
describe('useFavicon', () => { | ||
it('no param', () => { | ||
const favicon = useFavicon() | ||
expect(favicon.value).toEqual(null) | ||
favicon.value = 'https://www.google.at/favicon.ico' | ||
expect(favicon.value).toEqual('https://www.google.at/favicon.ico') | ||
}) | ||
|
||
it('const', () => { | ||
const favicon = useFavicon('v1') | ||
expect(favicon.value).toEqual('v1') | ||
favicon.value = 'v2' | ||
expect(favicon.value).toEqual('v2') | ||
}) | ||
|
||
it('null', () => { | ||
const favicon = useFavicon(null) | ||
expect(favicon.value).toEqual(null) | ||
favicon.value = 'v1' | ||
expect(favicon.value).toEqual('v1') | ||
}) | ||
|
||
it('undefined', () => { | ||
const favicon = useFavicon(undefined) | ||
expect(favicon.value).toEqual(null) | ||
favicon.value = 'v1' | ||
expect(favicon.value).toEqual('v1') | ||
}) | ||
|
||
it('ref const', () => { | ||
const tagetRef = ref('v1') | ||
const favicon = useFavicon(tagetRef) | ||
expect(favicon.value).toEqual('v1') | ||
tagetRef.value = 'v2' | ||
expect(favicon.value).toEqual('v2') | ||
}) | ||
|
||
it('ref null', () => { | ||
const tagetRef = ref(null) | ||
const favicon = useFavicon(tagetRef) | ||
expect(favicon.value).toEqual(null) | ||
}) | ||
|
||
it('ref undefined', () => { | ||
const favicon = useFavicon(ref(undefined)) | ||
expect(favicon.value).toEqual(undefined) | ||
}) | ||
|
||
it('computed/readonly', () => { | ||
const onoff = ref(1) | ||
const target = computed(() => onoff.value === 1 ? 'a.jpg' : 'b.jpg') | ||
const favicon = useFavicon(target) | ||
expect(favicon.value).toEqual('a.jpg') | ||
onoff.value = 2 | ||
expect(favicon.value).toEqual('b.jpg') | ||
// favicon.value = '1' | ||
}) | ||
|
||
it('function/readonly', () => { | ||
const target = () => 'a.jpg' | ||
const favicon = useFavicon(target) | ||
expect(favicon.value).toEqual('a.jpg') | ||
// favicon.value = '1' | ||
}) | ||
}) |
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