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
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
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
230
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
380
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
130
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
330
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
act2-costs.pdf
sumedhbala
0
110
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
920
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.7k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
0
160
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
460
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
The SEO Collaboration Effect
kristinabergwall1
1
500
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Embracing the Ebb and Flow
colly
88
5.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Spectacular Lies of Maps
axbom
PRO
1
860
Building AI with AI
inesmontani
PRO
1
1.1k
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!