Created
November 2, 2018 19:21
-
-
Save InfoSec812/fe2bbdd7bdf3be8c838e8e817e224881 to your computer and use it in GitHub Desktop.
Vue Test Utils Example
This file contains hidden or 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
| import { | |
| shallowMount | |
| } from '@vue/test-utils' | |
| import List from '@/components/List.vue' | |
| import { | |
| createRenderer | |
| } from 'vue-server-renderer' | |
| describe('List.vue', () => { | |
| it('renders li for each item in props.items', () => { | |
| const items = ['', ''] | |
| const wrapper = shallowMount(List, { | |
| propsData: { items } | |
| }) | |
| expect(wrapper.findAll('li')).toHaveLength(items.length) | |
| }) | |
| it('matches snapshot', () => { | |
| const items = ['item 1', 'item 2'] | |
| const renderer = createRenderer() | |
| const wrapper = shallowMount(List, { | |
| propsData: { items } | |
| }) | |
| renderer.renderToString(wrapper.vm, (err, str) => { | |
| if (err) throw new Error(err) | |
| expect(str).toMatchSnapshot() | |
| }) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment