Maxence Poutord - @_maxpou
Maxence Poutord - @_maxpou
Β© Kent C. Dodds
Yes I know it can be annoying... but it catches:
β‘ Helps to focus on what really matter β€οΈ
π¨π»βπΌ easily extendable - i.e. companies internal rules
Method AAA - Arrange-Act-Assert
Treat your component as a black box
High coverage !== bug proof
const vatCalculator = require('./vatCalculator') it('return the expected VAT', () => { const menu = [ { item: 'πΊ', price: 3 }, { item: 'π', price: 5.5 } ] console.log(vatCalculator(menu)) });
// 3.55
const vatCalculator = require('./vatCalculator')
it('return the expected VAT', () => {
const menu = [
{ item: 'πΊ', price: 3 },
{ item: 'π', price: 5.5 }
]
expect(vatCalculator(menu)).toBe(3.55)
});
const vatCalculator = require('./vatCalculator')
it('return the expected VAT', () => {
const menu = [
{ item: 'πΊ', price: 3 },
{ item: 'π', price: 5.5 }
]
expect(vatCalculator(menu)).toMatchSnapshot()
});
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`return the expected VAT 1`] = `3.55`;
it('should render correctly', () => {
const wrapper = mount(Alert, {
propsData: {
message: 'Test message',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
exports[`Alert.vue should render correctly 1`] = `
"
Test message
"
`;
shallowMount
)π eslint: jest/no-large-snapshots (default: 12 lines)
import { render, screen } from '@testing-library/vue'
import App from '../src/pages/App.vue'
it('should render a product', () => {
render(App)
screen.getByText('Calzone')
screen.getByText('The best pizza ever!')
screen.getByText('$8.00')
})
import { render, screen } from '@testing-library/vue'
import App from '../src/pages/App.vue'
it('should add items to basket', async () => {
await render(App)
await fireEvent.click(screen.getByLabelText('Add Calzone'))
await fireEvent.click(screen.getByLabelText('Add Margherita'))
await fireEvent.click(screen.getByLabelText('Add Margherita'))
expect(screen.getByRole('navigation')).toHaveTextContent('Basket (3)')
await fireEvent.click(screen.getByText('Basket (3)'))
await screen.findByText('Total')
screen.getByText('$19.00')
})
// it('should...', () => {
// expect(actions.resetStore).toHaveBeenCalled();
// expect(actions.getXXX).toHaveBeenCalled();
// expect(actions.getYYY).toHaveBeenCalled();
// });