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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
スマートグラスで並列バイブコーディング
hyshu
0
230
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
210
JavaDoc 再入門
nagise
1
370
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.6k
Performance Engineering for Everyone
elenatanasoiu
0
190
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
890
Oxcを導入して開発体験が向上した話
yug1224
4
320
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
350
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
200
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
dRuby over BLE
makicamel
2
380
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
sira's awesome portfolio website redesign presentation
elsirapls
0
280
Ethics towards AI in product and experience design
skipperchong
2
310
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
170
Crafting Experiences
bethany
1
180
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
Building Adaptive Systems
keathley
44
3.1k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
For a Future-Friendly Web
brad_frost
183
10k
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!