<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gatsby RSS feed]]></title><description><![CDATA[Personal blog of Damian Poole]]></description><link>http://github.com/dylang/node-rss</link><generator>GatsbyJS</generator><lastBuildDate>Sat, 06 Apr 2024 16:36:52 GMT</lastBuildDate><item><title><![CDATA[Animating Lightning Web Components on first render]]></title><link>https://proverbialmonkey.co.uk/animation-on-lwc-first-render/</link><guid isPermaLink="false">https://proverbialmonkey.co.uk/animation-on-lwc-first-render/</guid><pubDate>Mon, 12 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;With this post I hopefully am going to explain how and why CSS animations behave
the way they do with Lightning Web Components. The scope of this project is simple,
we want to make an element within a LWC animate it’s width when it is first placed into
the DOM. We are not relying on any data being provided via a remote request or a
method of this component being called by a parent.&lt;/p&gt;&lt;p&gt;The HTML is really simple;&lt;/p&gt;&lt;pre class=&quot;prism-code language-html&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;And the CSS we are going to apply;&lt;/p&gt;&lt;pre class=&quot;prism-code language-css&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token selector class&quot; style=&quot;color:#D8DEE9&quot;&gt;.bar&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token property&quot; style=&quot;color:#5a9bcf&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; hotpink&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token property&quot; style=&quot;color:#5a9bcf&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token number&quot; style=&quot;color:#5a9bcf&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token unit&quot;&gt;px&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token property&quot; style=&quot;color:#5a9bcf&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token number&quot; style=&quot;color:#5a9bcf&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token unit&quot;&gt;px&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token selector class&quot; style=&quot;color:#D8DEE9&quot;&gt;.bar.bar-grow&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token property&quot; style=&quot;color:#5a9bcf&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token number&quot; style=&quot;color:#5a9bcf&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token unit&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token property&quot; style=&quot;color:#5a9bcf&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; width &lt;/span&gt;&lt;span class=&quot;token number&quot; style=&quot;color:#5a9bcf&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token unit&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; linear&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;We are going to use the renderedCallback to start our animation after the component
is rendered for the first time. Update the HTML template to use a getter for the class
property.&lt;/p&gt;&lt;pre class=&quot;prism-code language-html&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{barClass}&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token maybe-class-name&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;lwc&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;Bar&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;extends&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  animate &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;renderedCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;animate&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;barClass&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token template-string string&quot; style=&quot;color:#8dc891&quot;&gt;`bar &lt;/span&gt;&lt;span class=&quot;token template-string interpolation interpolation-punctuation punctuation&quot; style=&quot;color:#8dc891&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token template-string interpolation keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token template-string interpolation punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token template-string interpolation&quot;&gt;animate &lt;/span&gt;&lt;span class=&quot;token template-string interpolation operator&quot; style=&quot;color:#d7deea&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token template-string interpolation&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token template-string interpolation string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;bar-gow&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token template-string interpolation&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token template-string interpolation punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token template-string interpolation&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token template-string interpolation string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token template-string interpolation interpolation-punctuation punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token template-string string&quot; style=&quot;color:#8dc891&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;But wait, theres a problem. If you run this code what you will see is the bar will
be full width and the animation has not run, instead it has immediately been set
to the end state of the transition.&lt;/p&gt;&lt;p&gt;A common approach I have seen is to use a timeout to change the animation property,
like so;&lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;renderedCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;animate&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;Before I attempt to explain what is going on here here is another way to achieve this
result without the &lt;strong&gt;setTimeout&lt;/strong&gt;.&lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;renderedCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;_firstRender&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;animate&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token boolean&quot; style=&quot;color:#ff8b50&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;.bar&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;offsetLeft&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;So what is going on here?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;LWC rerenders using a microtask, changing a reactive property is not immediate, this is why
you can change a reactive property multiple times in a piece of code like an event handler
but only the last value that was set is what is actually rendered.&lt;/p&gt;&lt;p&gt;So when our component initially is inserted into the DOM and animate is set to false
this is done during a microtask. By changing the animate property we are triggering another
microtask to be executed to potentially rerender the element.&lt;/p&gt;&lt;p&gt;By enqueing another microtask the event loop has not proceeded therefore the rendering
stage has not happened and the UI thread which handles paint etc has not done anything.&lt;/p&gt;&lt;p&gt;Once the second microtask has happened we have updated the DOM again and now the queue is
empty therefore the event loop continues and we render the changed DOM. This is why the
first example just immediately showed the bar as being 100% width.&lt;/p&gt;&lt;p&gt;Now with the setTimeout example we are enqueing the property change to a task, not a microtask.
This means once the microtask queue is empty the render stage will happen and then the next
available task will be picked up an executed. We’ve effectively created a delay in changing
the property.&lt;/p&gt;&lt;p&gt;And finally the working version without a timeout, what is going on here. Certain properties
cause the immediate invalidation and recalculation of layout. This is called layout thrashing
and this helps us in our example by ensuring that the layout knows about the element having zero
width. So when we apply the transition class it correctly causes the transition to happen.&lt;/p&gt;&lt;p&gt;Layout thrashing generally is something you want to avoid, it is a common cause of application
performance problems, especially large single page applications.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;As always the most important thing is to understand the concepts so you know when it makes
sense to use them and when they will cause you issues.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Mocking the initial state of the Lightning Web Component]]></title><link>https://proverbialmonkey.co.uk/lwc-test-initial-state/</link><guid isPermaLink="false">https://proverbialmonkey.co.uk/lwc-test-initial-state/</guid><pubDate>Tue, 14 Apr 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Jest is a great tool for testing, there are so many different ways to solve testing
problems. I want to talk about a problem I have encountered and go over a solution
to it while testing lightning web components.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Now this technique has a specific use case which I want to make clear. It should
not be how you test components by default, there are already loads of examples of
that specifically in the
&lt;a href=&quot;https://developer.salesforce.com/docs/component-library/documentation/en/lwc&quot;&gt;LWC documentation&lt;/a&gt;
and &lt;a href=&quot;https://github.com/trailheadapps/lwc-recipes&quot;&gt;LWC recipes&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;My simple use case is this; we have a existing component which is a simple form
with multiple inputs. We already have tests to ensure our wiring and validation
works etc.&lt;/p&gt;&lt;p&gt;So for this example I have initially created a simple component which an obvious issue.&lt;/p&gt;&lt;pre class=&quot;prism-code language-html&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{state.firstName}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;Enter your first name&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;onchange&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{handleChange}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;surname&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{state.surname}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;Enter your surname&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;onchange&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{handleChange}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{buttonClasses}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;disabled&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{invalid}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token tag attr-name&quot; style=&quot;color:#c5a5c5&quot;&gt;onclick&lt;/span&gt;&lt;span class=&quot;token tag attr-value punctuation&quot; style=&quot;color:#8dc891&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token tag attr-value&quot; style=&quot;color:#8dc891&quot;&gt;{handleSave}&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            Save&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token tag&quot; style=&quot;color:#fc929e&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;token tag punctuation&quot; style=&quot;color:#8dc891&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token maybe-class-name&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;lwc&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; setState &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; newState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;newState &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;extends&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    state &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        firstName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        surname&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;handleChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;updateState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;handleSave&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;A&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;throw&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;BOOM&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;updateState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;newState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;setState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; newState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;We’ve had a bug reported that when the form is filled in with specific
values and it is submitted it causes an error.&lt;/p&gt;&lt;p&gt;Normally when you are testing these kind of state interactions you would do something
like this in your test. &lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; input &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;input&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;dispatchEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;CustomEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;change&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;Now this works fine for a simple component but when you get more complex components
you will need to dispatch more of these changes and potentially in specific orders.&lt;/p&gt;&lt;p&gt;In order to effectively test this issue however, we would want to have our components
initial state be set to what the reported values are. That way we don’t need find
all the inputs and dispatch events for each one. Again my example is simple so this
step of dispatching events could be fairly complex.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;This is not to say don’t think about appropriate composition of your components
but you may be inheriting bad practice etc.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;So with that in mind we want a simple way of setting some default state values for
our component which could be complex in nature.&lt;/p&gt;&lt;p&gt;The first thing we are going to need to do is to create a module which will provide
the default values for our state object and also a means of mocking them to be
something else.&lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token constant&quot; style=&quot;color:#5a9bcf&quot;&gt;DEFAULT_STATE&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    firstName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    surname&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;We’ll make some tweaks to our component to consume it.&lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token maybe-class-name&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;lwc&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token constant&quot; style=&quot;color:#5a9bcf&quot;&gt;DEFAULT_STATE&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;./constants&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;extends&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token class-name&quot; style=&quot;color:#FAC863&quot;&gt;LightningElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    state &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token constant&quot; style=&quot;color:#5a9bcf&quot;&gt;DEFAULT_STATE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;Now that we have done this we can now write our test using &lt;code&gt;jest.doMock&lt;/code&gt;&lt;/p&gt;&lt;pre class=&quot;prism-code language-javascript&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token function-variable function&quot; style=&quot;color:#79b6f2&quot;&gt;createComponent&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;config &lt;/span&gt;&lt;span class=&quot;token parameter operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token parameter punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token parameter punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt; cmpClass&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; component &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;my-app&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        is&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; cmpClass&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token known-class-name class-name&quot; style=&quot;color:#FAC863&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; config&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token dom variable&quot; style=&quot;color:#d7deea&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;shadowRoot&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;my-app&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;afterEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token dom variable&quot; style=&quot;color:#d7deea&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;firstChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token dom variable&quot; style=&quot;color:#d7deea&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token dom variable&quot; style=&quot;color:#d7deea&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;firstChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;beforeEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token comment&quot; style=&quot;color:#999999&quot;&gt;// we need to ensure module mocks are reset per test&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        jest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;resetModules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token comment&quot; style=&quot;color:#999999&quot;&gt;// resetting modules means we need to re-import createElement&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;let&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; create &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;lwc&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        createElement &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;Should not throw and error when firstName is A&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        jest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;doMock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;../constants.js&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token arrow operator&quot; style=&quot;color:#d7deea&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; originalModule &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; jest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;requireActual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;../constants.js&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;originalModule&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;token constant&quot; style=&quot;color:#5a9bcf&quot;&gt;DEFAULT_STATE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;                    &lt;/span&gt;&lt;span class=&quot;token spread operator&quot; style=&quot;color:#d7deea&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;originalModule&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot; style=&quot;color:#5a9bcf&quot;&gt;DEFAULT_STATE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;                    firstName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;A&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;                &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;            &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token maybe-class-name&quot;&gt;MyApp&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;my/app&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token keyword&quot; style=&quot;color:#c5a5c5&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; root &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token operator&quot; style=&quot;color:#d7deea&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;createComponent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token maybe-class-name&quot;&gt;MyApp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword module&quot; style=&quot;color:#c5a5c5&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token function&quot; style=&quot;color:#79b6f2&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;input&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token property-access&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token method function property-access&quot; style=&quot;color:#79b6f2&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot; style=&quot;color:#8dc891&quot;&gt;&amp;#x27;A&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot; style=&quot;display:inline-block&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;token comment&quot; style=&quot;color:#999999&quot;&gt;// Now we can test our failing logic when we call `handleSave`&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot; style=&quot;color:#8dc891&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;I have &lt;a href=&quot;https://github.com/damianpoole/lwc-initial-state-testing&quot;&gt;created a much more comprehensive repo&lt;/a&gt; with further test examples showing how
you would blend these technique with a standard way of testing your component. You
could also always have separate test files for these so that you do not need to modify
all you existing tests too.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Running Siesta tests from Atom or Sublime]]></title><link>https://proverbialmonkey.co.uk/siesta-atom-sublime/</link><guid isPermaLink="false">https://proverbialmonkey.co.uk/siesta-atom-sublime/</guid><pubDate>Sat, 20 Dec 2014 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This post is not about how to use Siesta for unit testing, more a quick guide on how to
get setup using PhatomJS to run your tests from Atom or Sublime.&lt;/p&gt;&lt;p&gt;The main benefit to using this over the standard web ui is speed. From a keyboard shortcut you can have your test pass or fail within a second.&lt;/p&gt;&lt;h3&gt;Atom&lt;/h3&gt;&lt;p&gt;My current IDE of choice so i’ll go over the setup for this one first.&lt;/p&gt;&lt;p&gt;Firstly &lt;a href=&quot;https://github.com/noseglid/atom-build&quot;&gt;install this package&lt;/a&gt; which allows you to build your current project directly from atom.&lt;/p&gt;&lt;p&gt;Once you have done that all you no need to do is create a .atom-build.json file which tells the package how to build your project.&lt;/p&gt;&lt;p&gt;Example .atom-build.json file.&lt;/p&gt;&lt;pre class=&quot;prism-code language-&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &amp;quot;cmd&amp;quot;: &amp;quot;PATH_TO_SIESTA/bin/phantomjs&amp;quot;,&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &amp;quot;args&amp;quot;: [ &amp;quot;LOCALHOST/test.html&amp;quot;, &amp;quot;--filter {FILE_ACTIVE_NAME}&amp;quot;],&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &amp;quot;sh&amp;quot;: true&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;By using —filter we are telling PhantomJS to only run the test we are looking at within our IDE.&lt;/p&gt;&lt;h3&gt;Sublime&lt;/h3&gt;&lt;p&gt;Luckily Sublime supports build systems out of the box so no packages are needed to be installed.&lt;/p&gt;&lt;p&gt;To create a new build system go tools &amp;gt; build systems &amp;gt; new build system.&lt;/p&gt;&lt;p&gt;Example siesta.sublime-build.&lt;/p&gt;&lt;pre class=&quot;prism-code language-&quot; style=&quot;background-color:#282c34;color:#ffffff&quot;&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &amp;quot;cmd&amp;quot; : [&amp;quot;PATH_TO_SIESTA/bin/phantomjs LOCALHOST/test.html --filter $file_name&amp;quot;],&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;  &amp;quot;shell&amp;quot;: true&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;token-line&quot; style=&quot;color:#ffffff&quot;&gt;&lt;span class=&quot;token plain&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;p&gt;Now you just need to ensure you are using this build system for your project and you can now run a single test just like in Atom.&lt;/p&gt;</content:encoded></item></channel></rss>