2019/08/17
CaT vol.7 in 秋田 / Short LT
module.exports = {
presets: [
'@vue/app',
[
'@babel/preset-env',
{
targets: {
browsers: ['> 1%', 'last 2 versions'],
node: 'current'
},
useBuiltIns: 'entry',
corejs: 3
}
]
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true
}
],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-syntax-dynamic-import'
]
}
.
├── doc_root
│ ├── app
│ ├── tests
│ └── webroot
├── frontend
│ ├── public
│ ├── src
│ │ ├── api
│ │ ├── assets
│ │ ├── components
│ │ ├── plugins
│ │ ├── services
│ │ ├── types
│ │ ├── utils
│ │ └── views
│ └── tests
// @testing-library/vue
import '@testing-library/jest-dom/extend-expect'
import { render, fireEvent } from '@testing-library/vue'
describe('Button', () => {
it('click event', async () => {
const { getByText } = render(Child, {
propsData: {
text: '追加する'
}
})
const button = getByText('追加する')
await fireEvent.click(button)
})
})
// @vue/test-utils
import { createLocalVue } from '@vue/test-utils'
// bootstrap-vue
import BootstrapVue from 'bootstrap-vue'
const localVue = createLocalVue()
localVue.use(BootstrapVue)
describe('Button', () => {
it('click event', async () => {
const { getByText } = render(Child, {
localVue,
propsData: {
text: '追加する'
}
})
const button = getByText('追加する')
await fireEvent.click(button)
})
})
import axios from 'axios';
import { Sale } from '@/types';
export default class SaleService {
public async fetchSummary(
id: number
): Promise<Sale> {
const res = await axios.get(`/summary?id=${id}`);
return res.data;
}
}
import SaleService from '@/services/SaleService';
describe('SaleService', () => {
let saleService: SaleService;
beforeEach(() => {
saleService = new SaleService();
});
it('fetch data', async () => {
const responseData = await saleService.fetchSummary(
null
);
expect(responseData.id).toBe(1);
});
})
describe('Service', () => {
let mockAxios: MockAdapter
beforeEach(() => {
// あえてモックの返却を遅らせる
mockAxios = new MockAdapter(axios, {
delayResponse: 500
})
})
it('response status === 403', async () => {
mockAxios.onGet(`${BASE_API}1`)
.reply(403)
try {
await getPostID(1)
} catch (error) {
expect(error.message).toEqual('Request failed with status code 403');
}
})
})