Skip to content

Commit

Permalink
test: add failing global mocks scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodeleao committed Jan 3, 2023
1 parent 802c7e4 commit cc1bd39
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/mountingOptions/mocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,29 @@ describe('mocks', () => {
expect(wrapper.text()).toContain('hello')
expect(wrapper.text()).toContain('mocked')
})

it('mocks a global function in an option component which includes the setup() option', () => {
const ComponentWithI18nAndSetupOption = defineComponent({
setup: () => ({
hello: 'hello'
}),
template: `
<div>{{ hello }}</div>
<!-- this emulates components that use a global function like $t for i18n -->
<!-- this function can be mocked using global.mocks -->
<div>{{ $t('world') }}</div>
`
})

const wrapper = mount(ComponentWithI18nAndSetupOption, {
global: {
mocks: {
$t: () => 'mocked'
}
}
})

expect(wrapper.text()).toContain('hello')
expect(wrapper.text()).toContain('mocked')
})
})

0 comments on commit cc1bd39

Please sign in to comment.