<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thiago de Bastos</title>
    <description>The latest articles on DEV Community by Thiago de Bastos (@thiagodebastos).</description>
    <link>https://dev.to/thiagodebastos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F136434%2F20892966-d196-445a-a91a-80a3eb3f63c3.jpeg</url>
      <title>DEV Community: Thiago de Bastos</title>
      <link>https://dev.to/thiagodebastos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thiagodebastos"/>
    <language>en</language>
    <item>
      <title>Regular vs Non-Breaking Spaces  </title>
      <dc:creator>Thiago de Bastos</dc:creator>
      <pubDate>Thu, 26 Aug 2021 11:17:45 +0000</pubDate>
      <link>https://dev.to/thiagodebastos/regular-vs-non-breaking-spaces-1e5a</link>
      <guid>https://dev.to/thiagodebastos/regular-vs-non-breaking-spaces-1e5a</guid>
      <description>&lt;p&gt;Today at work I came across a failing test that made me wonder if the previous&lt;br&gt;
developer had just given up and left it fail. The failing test looked to be comparing&lt;br&gt;
two identical strings but failing at the spaces.&lt;/p&gt;

&lt;p&gt;To replicate this issue, you can fire up the &lt;a href="https://nodejs.dev/learn/how-to-use-the-nodejs-repl"&gt;NodeJS&lt;br&gt;
REPL&lt;/a&gt; and follow along.&lt;/p&gt;

&lt;p&gt;NOTE: Each &lt;code&gt;&amp;gt;&lt;/code&gt; is a command to be executed in the REPL.&lt;/p&gt;

&lt;p&gt;I've highlighted parts to take note of.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜  ~ node
Welcome to Node.js v16.7.0.
Type ".help" for more information.
&amp;gt; const assert = require('assert')
undefined
&amp;gt; const nonBreakingSpace = '\u00a0'
undefined
&amp;gt; const space = ' '
undefined
&amp;gt; assert.strictEqual(nonBreakingSpace, space);
Uncaught AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

' ' !== ' '

    at REPL4:1:8
    at Script.runInThisContext (node:vm:129:12)
    at REPLServer.defaultEval (node:repl:562:29)
    at bound (node:domain:421:15)
    at REPLServer.runBound [as eval] (node:domain:432:12)
    at REPLServer.onLine (node:repl:889:10)
    at REPLServer.emit (node:events:406:35)
    at REPLServer.emit (node:domain:475:12)
    at REPLServer.Interface._onLine (node:readline:487:10)
    at REPLServer.Interface._line (node:readline:864:8) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: ' ',
  expected: ' ',
  operator: 'strictEqual'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In HTML, &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt;'s are used to prevent two words from breaking or wrapping&lt;br&gt;
at the end of a line.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Looking at the log above, it is not immediately obvious what is going on. This&lt;br&gt;
is even less obvious when the spaces exist in a sentence, or when the text&lt;br&gt;
exists in html as something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;This&lt;span class="ni"&gt;&amp;amp;nbsp;&lt;/span&gt;will&lt;span class="ni"&gt;&amp;amp;nbsp;&lt;/span&gt;bite!&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When this is rendered by a React testing library, the &lt;code&gt;&amp;amp;nbsp;&lt;/code&gt; will appear&lt;br&gt;
identical to a normal space when rendered.&lt;/p&gt;

&lt;p&gt;I had a suspicion it was an issue with ASCII characters only because I remember&lt;br&gt;
an &lt;a href="https://stackoverflow.com/questions/26965331/javascript-prank-joke#26965332"&gt;old&lt;br&gt;
prank&lt;/a&gt;&lt;br&gt;
regarding replacing semicolons &lt;code&gt;;&lt;/code&gt; with the Greek question mark &lt;code&gt;;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I fixed the breaking test by entering the actual ASCII code instead of the&lt;br&gt;
copy-pasted space.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;strictEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Don't&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;u00a0break&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;u00a0me&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>tdd</category>
      <category>gotchya</category>
    </item>
  </channel>
</rss>
