Skip to content

Instantly share code, notes, and snippets.

@kuroski
Last active October 25, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuroski/6ef9b697bb7969022cf70afe7969d89c to your computer and use it in GitHub Desktop.
Save kuroski/6ef9b697bb7969022cf70afe7969d89c to your computer and use it in GitHub Desktop.
import { shallowMount } from '@vue/test-utils'
import VUserProfile from '@/components/VUserProfile'
import user from './fixtures/user'
describe('VUserProfile', () => {
let props
const build = () => {
const wrapper = shallowMount(VUserProfile, {
propsData: props,
})
return {
wrapper,
avatar: () => wrapper.find('.user-profile__avatar'),
name: () => wrapper.find('.user-profile__name'),
bio: () => wrapper.find('.user-profile__bio'),
}
}
beforeEach(() => {
props = {
user
}
})
it('renders the component', () => {
// arrange
const { wrapper } = build()
// assert
expect(wrapper.html()).toMatchSnapshot()
})
it('renders main components', () => {
// arrange
const { avatar, name, bio } = build()
// assert
expect(avatar().exists()).toBe(true)
expect(avatar().attributes().src).toBe(props.user.avatar_url)
expect(name().exists()).toBe(true)
expect(name().text()).toBe(props.user.name)
expect(bio().exists()).toBe(true)
expect(bio().text()).toBe(props.user.bio)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment