Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SVG makes your components to testable
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
KIMURA Tetsuro
May 23, 2018
Programming
2.2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SVG makes your components to testable
Vue.js Tokyo v-meetup #7
KIMURA Tetsuro
May 23, 2018
More Decks by KIMURA Tetsuro
See All by KIMURA Tetsuro
Nuxt.jsによるAdobe MAX Japan 2018公式Webサイト制作の舞台裏
haribote
11
3.8k
Other Decks in Programming
See All in Programming
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
350
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
240
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
210
AIエージェントで 変わるAndroid開発環境
takahirom
2
480
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
560
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
480
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
320
Vite+ Unified Toolchain for the Web
naokihaba
0
730
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
240
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
460
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Automating Front-end Workflow
addyosmani
1370
210k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
Code Review Best Practice
trishagee
74
20k
First, design no harm
axbom
PRO
2
1.2k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
450
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Transcript
SVG makes your components to testable Vue.js Tokyo v-meetup #7
2018/05/23 Wed
KIMURA Tetsuro
Resources of Vue with SVG • Sarah Drasner Animating Vue
• ͬ͠ΎΖͬ͘ άϦάϦಈ͘UIΛVueͱSVGͰαΫοͱॻ͘ • Me Vue.jsͰD3.jsΛΘͣʹάϥϑΛ࣮͢Δ
This is a simple story. Yeah, it’s about testing.
Are you testing?
I guess, almost YES.
How about GRAPHICAL components?
None
<canvas> •How to SPEC rendering result? •What is the EXPECTED?
It’s NOT easy.
SVG is CODE.
It’s EXPECTABLE. And…
Today, we have SNAPSHOT TESTING by Jest!!
#vue-cli ? Pick a unit testing solution: Mocha + Chai
> Jest “vue-server-renderer” is not necessary. Just choose this.
1.Create a component. 2.Write static / rough template. 3.Generate the
first snapshot.
Like this.
Mark up it. <template> <div class="p-chart-line"> <svg viewBox="0 0 1000
700" width="1000" height="700"> <g transform="translate(50, 50)"> <g stroke="#ccc" stroke-width="1"> <path d="M 0 .5 H 900" stroke="#999" transform="translate(0, 600)"></path> <path d="M 0 .5 H 900" transform="translate(0, 450)"></path> <path d="M 0 .5 H 900" transform="translate(0, 300)"></path> <path d="M 0 .5 H 900" transform="translate(0, 150)"></path> <path d="M 0 .5 H 900"></path> </g> <g fill="none" stroke-width="3" transform="translate(50, 600)"> <polyline points="0 -60 160 -300 320 -240 480 -450 640 -360 800 -540" stroke="#000080" ></polyline> </g> </g> </svg> </div> </template>
Write testing code. import { shallowMount } from '@vue/test-utils' import
ChartLine from '@/components/ChartLine.vue' describe('ChartLine.vue', () => { it('matches snapshot', () => { const values = [.1, .5, .4, .75, .6, .9] const wrapper = shallowMount(ChartLine, { propsData: { values } }) expect(wrapper.html()).toMatchSnapshot() }) })
npm run test:unit Run tests.
It was generated. // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ChartLine.vue matches
snapshot 1`] = ` <div class="p-chart-line"> <svg viewBox="0 0 1000 700" width="1000" height="700"> <g transform="translate(50, 50)"> <g stroke="#ccc" stroke-width="1"> <path d="M 0 .5 H 900" stroke="#999" transform="translate(0, 600)"></path> <path d="M 0 .5 H 900" transform="translate(0, 450)"></path> <path d="M 0 .5 H 900" transform="translate(0, 300)"></path> <path d="M 0 .5 H 900" transform="translate(0, 150)"></path> <path d="M 0 .5 H 900"></path> </g> <g fill="none" stroke-width="3" transform="translate(50, 600)"> <polyline points="0 -60 160 -300 320 -240 480 -450 640 -360 800 -540" stroke="#000080"></polyline> </g> </g> </svg> </div> `;
Now, the expecting has defined.
It’s time to build LOGICS!
npm run test:unit —- -u Update snapshots.
Oh by the way, SVG presents DOM.
Here's the thing. // template <polyline class="p-chart-line__line" @click="handleClick" ></polyline> //
testing describe('.p-chart-line__line@click', () => { it('emits a `click-line` event', () => { const wrapper = shallowMount(ChartLine) wrapper.find('.p-chart-line__line').trigger('click') expect(wrapper.emitted('click-line')[0]).toEqual([]) }) }) // methods handleClick() { this.$emit('click-line') }
It’s easy to bind events. And testing too.
All right, we’ve got testable components now. SVG helps you!
Thank you!