Skip to content

Commit

Permalink
fix: isString should properly guard string type
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusBorg committed Nov 7, 2022
1 parent b4b15bd commit 1629187
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions src/__tests__/advanced.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, test, expect, vi } from 'vitest'
import { createComposableFromMixin } from '../createComposable'
import { defineMixin } from '../defineMixin'
import { wrapComposable } from './helpers'

describe('advanced', () => {
test('nested mixins', async () => {
const innerSpy = vi.fn()
const outerSpy = vi.fn()
const innerMixin = defineMixin({
props: {
inner: Number,
},
data: () => ({
nestedProperty: 'A',
sharedProperty: 'A',
}),
created() {
innerSpy()
},
mounted() {
innerSpy()
},
})
const outerMixin = defineMixin({
mixins: [innerMixin],
props: {
outer: String,
},
data: () => ({
msg: 'Hello World',
sharedProperty: 'B',
}),
computed: {
getNestedProperty(): string {
return this.nestedProperty
},
},
mounted() {
outerSpy()
},
})
const innerComposable = createComposableFromMixin(innerMixin)

const outerComposable = createComposableFromMixin(outerMixin)
const wrapper = wrapComposable(
outerComposable,
{
props: {
outer: 'Hello',
inner: 10,
},
},
{
props: outerComposable.props,
}
)
// Props
expect(wrapper.vm.outer).toBe('Hello')
expect(wrapper.vm.inner).toBe(10)
// Data & computed
expect(wrapper.vm.sharedProperty).toBe('B')
expect(wrapper.vm.getNestedProperty).toBe('A')
// Lifecycle Hooks
expect(innerSpy).toHaveBeenCalledTimes(2)
expect(outerSpy).toHaveBeenCalledTimes(1)
})
})
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const isFunction = (val: unknown): val is Function =>
export const isArray = Array.isArray
export const isObject = (val: unknown): val is Record<any, any> =>
val !== null && typeof val === 'object'
export const isString = (val: unknown): val is String => typeof val === 'string'
export const isString = (val: unknown): val is string => typeof val === 'string'

/**
* @legal
Expand Down

0 comments on commit 1629187

Please sign in to comment.