~ Part 1 ~
“Test a single concept in each test function”
- Uncle Bob (Clean Code)
it ('should display a formatted username', () => {});
it ('should display a formatted username with a custom
avatar', () => {});
it ('should display a formatted username in green with
a custom avatar if the user is logged in, otherwise
it should display a generic avatar and display the
username in red', () => {});
describe('AddButton.vue', () => {
describe(':props', () => {
it(':label - should render a button with the passed-in label text', () => {
})
});
describe('@events', () => {
it('@add - should emit an "add" event when the button is clicked', () => {
})
});
})
Confidence to Change / Removal of Fear +
**Developer Happiness**
High Code Quality +
Well-Documented Code =
~ Part 2 ~
Props
Events
User Interaction
Rendered Output
MyComponent
Lifecycle
Methods
Test the Public Interface!
Connection with
Children
If there's logic in the template we should test it
Avoriaz
Props
Rendered Output
UserSettingsBar
Testing template logic
Implementation Details
SquareButton.spec.js
Events
User Interaction
SquareButton
Testing the framework itself
<p>{{myProp}}</p>
expect(p.text()).to.be(/* some prop value */)
Prop validation
1
2
Vue
Us
✨ Trust the framework ✨
Integration
Shallow
Test the component with the idea that sub components (and their subcomponents) are all part of it's "component contract"
Subcomponents more than one level down are not part of the component contract.
Integration
Counter.vue
CounterDisplay.vue
Button.vue
"increment" event
"count" prop
TEST
Find button element, trigger click
Find display element, assert render
Counter.spec.js
User Interaction
Rendered Output
Counter
Counter Integration Tests
Shallow
Counter.vue
CounterDisplay.vue
Button.vue
"increment" event
"count" prop
TEST
TEST
We don't care how this will be rendered
We don't care how this was triggered
Props
Counter
Counter
Display
Button
Props
Events
Counter Shallow Tests
Integration
Shallow
Maintainability
Coverage
Modularity
High
High
High
Medium/Low
Low
Medium
Tradeoffs
Want to learn more?
Avoriaz -> vue-test-utils
Snapshot Testing / Jest
E2E tests: Webdriver IO / Nightwatch
Testing Vuex
Thanks!
github: @matt-oconnell