Last active
June 3, 2020 12:24
-
-
Save dejanvasic85/55a97b019c26bfd96652ebbfc646a1a3 to your computer and use it in GitHub Desktop.
Jest Testing Examples
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
import React from 'react'; | |
import { Avatar } from 'antd'; | |
import { shallow, ShallowWrapper } from 'enzyme'; | |
import ColourAvatar from './ColourAvatar'; | |
describe('ColourAvatar', () => { | |
let wrapper: ShallowWrapper; | |
const defaultProps: any = { | |
firstName: 'Boom', | |
}; | |
describe('when only first name is provided', () => { | |
beforeEach(() => { | |
wrapper = shallow(<ColourAvatar {...defaultProps} />); | |
}); | |
it('should render Avatar', () => { | |
expect(wrapper.find(Avatar)).toHaveLength(1); | |
}); | |
it('should display first initial', () => { | |
expect(wrapper.find(Avatar).render().text()).toEqual('B'); | |
}); | |
it('should have large Avatar size', () => { | |
expect(wrapper.find(Avatar).prop('size')).toEqual('large'); | |
}); | |
it('should set background colour style', () => { | |
expect(wrapper.find(Avatar).prop('style').backgroundColor).toHaveLength(7); | |
}); | |
}); | |
describe('when last name is provided', () => { | |
beforeEach(() => { | |
wrapper = shallow(<ColourAvatar {...defaultProps} lastName="Shaka" />); | |
}); | |
it('should render both initials', () => { | |
expect(wrapper.find(Avatar).render().text()).toEqual('BS'); | |
}); | |
}); | |
describe('when the src attribute is provided', () => { | |
beforeEach(() => { | |
wrapper = shallow(<ColourAvatar {...defaultProps} src="http://jedigova" />); | |
}); | |
it('should render both initials', () => { | |
expect(wrapper.find(Avatar).prop('src')).toEqual('http://jedigova'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment