{"id":69,"date":"2019-04-08T19:48:24","date_gmt":"2019-04-08T19:48:24","guid":{"rendered":"http:\/\/yer.ac\/blog\/?p=69"},"modified":"2019-04-24T07:39:36","modified_gmt":"2019-04-24T07:39:36","slug":"attempting-to-use-mocha-chai-to-unit-test-es6","status":"publish","type":"post","link":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/","title":{"rendered":"Attempting to use Mocha &#038; Chai to unit test ES6."},"content":{"rendered":"\n<p>In this post I will cover using Mocha (JS test framework) and Chai (For BDD syntax) to unit test ES6 Javascript in VS Code.<\/p>\n\n\n\n<p>I started working on a small side project, for no reason other than to play with ES6+. It&#8217;s a(nother) relatively simple toast library written in as much vanilla JS as possible to avoid reliance on libraries &amp; packages.<\/p>\n\n\n\n<p>I got the code working, but I couldn&#8217;t prove that the functions worked. I used qUnit in the past to test JavaScript but if I am completely honest my JavaScript testing knowledge is a bit lacking. <\/p>\n\n\n\n<p>My aim is to get some unit tests for one of my main classes where I can test <strong>directly against ES6<\/strong> and not against the compiled ES5 code. I want the tests to be clear to what they are doing. What I am doing is not new at all, nor is the library! I just wanted to keep notes of how I achieved this first time around.<\/p>\n\n\n\n<p><strong>Disclaimer:<\/strong> This is by no means a comprehensive guide or walkthrough, just the results of me messing about to see if I can get the outcome I wanted whilst learning something new! <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enter, Mocha<\/h2>\n\n\n\n<p>I decided to use<a href=\"https:\/\/mochajs.org\/\">Mocha<\/a> to do my unit testing, which was chosen purely as it seemed to work well with ES6 code (using Babel). Later I will go into how I also used <a href=\"https:\/\/www.chaijs.com\/\">Chai <\/a>along side to provide much nicer, fluid assertions using BDD-style syntax.<\/p>\n\n\n\n<p>First of all, I had to install Mocha.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> npm install --save-dev mocha<\/code><\/pre>\n\n\n\n<p>Then under a new root folder of  &#8220;test&#8221; I created a bread.spec.js &#8211; where &#8220;bread&#8221; here is the name of the class I am testing.<\/p>\n\n\n\n<p>At this point it is fairly easy to create a simple test, like so.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import {Bread} from \"..\/src\/bread\";\nvar assert = require('assert');\ndescribe('Fluent methods', function() {\n  describe('Title set is not called', function() {\n    it('should set the title correctly (null)', function() {\n        let options = [ ... code to get options ... ]     \n        let b = new Bread(0,\"Foo\", options);       \n      assert.equal(b.Title, null);\n    });\n  });\n});<\/code><\/pre>\n\n\n\n<p>I then added the appropriate script to <strong>package.json<\/strong> to allow us to run the tests. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \"test\": \"mocha --require @babel\/polyfill --require @babel\/register '.\/test\/**\/*.spec.js'\"<\/code><\/pre>\n\n\n\n<p>Which is ran with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run-script test<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"244\" data-attachment-id=\"70\" data-permalink=\"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/image-13\/\" data-orig-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=604%2C244&amp;ssl=1\" data-orig-size=\"604,244\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=604%2C244&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?resize=604%2C244\" alt=\"VS code window with output of script above. Shows a single completed unit test.\" class=\"wp-image-70\" srcset=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?w=604&amp;ssl=1 604w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?resize=300%2C121&amp;ssl=1 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><figcaption>Output of running above command.<br><\/figcaption><\/figure>\n\n\n\n<p>This script states that it will run Mocha, on all files under the test directory where the JS file ends with &#8220;.spec.js&#8221;. I then had to add the 2 requires which enable Mocha to call the ES6 directly and not have to use the transpiled version. <strong>Failing to do provide these requires will mean Mocha will not run as it cannot parse ES6.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using Chai for BDD syntax<\/h2>\n\n\n\n<p>In the above, I import my class then create a &#8220;test set&#8221;. In this test set I then have a single test which is checking if the title gets automatically set. It&#8217;s fairly easy to attain what the test does, but it could be clearer. This is where I decided to use Chai. Chai will allow me to have a BDD-style test written which is closer to plain english. Mocha does support <em>some<\/em> of this (at time of writing) but Chai is much closer to BDD-style syntax I was used to.<\/p>\n\n\n\n<p>To use Chai I need to install the package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install --save-dev chai<\/code><\/pre>\n\n\n\n<p>Then  import the &#8220;expect&#8221; module from the framework, and refactor the method so it looks a little like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { expect } from \"chai\";\nimport {Bread} from \"..\/src\/bread\";\ndescribe(\"Fluent methods\", () => {\n    describe(\"Title set is not called\", () => {\n        it(\"should set the title correctly (null).\", () => {\n            var options = getValidOptions();            \n            let b = new Bread(0,\"Foo\", options);\n            expect(b.Title).to.equal(null);\n        });\n    });  \n)};<\/code><\/pre>\n\n\n\n<p>Running the tests will yield the same result as before, but now its a lot more readable (In my opinion!)<\/p>\n\n\n\n<p>Not a lot more to add really. Mocha and Chai both have great documentation  to read through. The only difficulty I had was getting Mocha to run ES6 directly, as a lot of the information online for this was out of date  (that I found&#8230;)<\/p>\n\n\n\n<p>Update: I have also posted about debugging using ES6 Mocha tests <a href=\"http:\/\/yer.ac\/blog\/2019\/04\/09\/debugging-es6-mocha-unit-tests-using-vs-code\/\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will cover using Mocha (JS test framework) and Chai (For BDD syntax) to unit test ES6 Javascript in VS Code. I started working on a small side project, for no reason other than to play with ES6+. It&#8217;s a(nother) relatively simple toast library written in as much vanilla JS as possible &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6,11],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-development","category-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Attempting to use Mocha &amp; Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.<\/title>\n<meta name=\"description\" content=\"Using Mocha and Chai to unit test ES6 Javascript in VS Code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Attempting to use Mocha &amp; Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.\" \/>\n<meta property=\"og:description\" content=\"Using Mocha and Chai to unit test ES6 Javascript in VS Code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/\" \/>\n<meta property=\"og:site_name\" content=\"yer.ac | Adventures of a developer, and other things.\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-08T19:48:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T07:39:36+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png\" \/>\n<meta name=\"author\" content=\"yer.ac\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"yer.ac\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/\"},\"author\":{\"name\":\"yer.ac\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"headline\":\"Attempting to use Mocha &#038; Chai to unit test ES6.\",\"datePublished\":\"2019-04-08T19:48:24+00:00\",\"dateModified\":\"2019-04-24T07:39:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/\"},\"wordCount\":595,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"image\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/image.png\",\"articleSection\":[\"Development\",\"Testing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/\",\"url\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/\",\"name\":\"Attempting to use Mocha & Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/image.png\",\"datePublished\":\"2019-04-08T19:48:24+00:00\",\"dateModified\":\"2019-04-24T07:39:36+00:00\",\"description\":\"Using Mocha and Chai to unit test ES6 Javascript in VS Code\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/image.png?fit=604%2C244&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/image.png?fit=604%2C244&ssl=1\",\"width\":604,\"height\":244},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/04\\\/08\\\/attempting-to-use-mocha-chai-to-unit-test-es6\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/yer.ac\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Attempting to use Mocha &#038; Chai to unit test ES6.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/yer.ac\\\/blog\\\/\",\"name\":\"yer.ac | Adventures of a developer, and other things.\",\"description\":\"Blog to keep track of things I am upto\",\"publisher\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/yer.ac\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\",\"name\":\"yer.ac\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"caption\":\"yer.ac\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Attempting to use Mocha & Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.","description":"Using Mocha and Chai to unit test ES6 Javascript in VS Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/","og_locale":"en_US","og_type":"article","og_title":"Attempting to use Mocha & Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.","og_description":"Using Mocha and Chai to unit test ES6 Javascript in VS Code","og_url":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/","og_site_name":"yer.ac | Adventures of a developer, and other things.","article_published_time":"2019-04-08T19:48:24+00:00","article_modified_time":"2019-04-24T07:39:36+00:00","og_image":[{"url":"http:\/\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png","type":"","width":"","height":""}],"author":"yer.ac","twitter_card":"summary_large_image","twitter_misc":{"Written by":"yer.ac","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#article","isPartOf":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/"},"author":{"name":"yer.ac","@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"headline":"Attempting to use Mocha &#038; Chai to unit test ES6.","datePublished":"2019-04-08T19:48:24+00:00","dateModified":"2019-04-24T07:39:36+00:00","mainEntityOfPage":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/"},"wordCount":595,"commentCount":1,"publisher":{"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"image":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#primaryimage"},"thumbnailUrl":"http:\/\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png","articleSection":["Development","Testing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/","url":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/","name":"Attempting to use Mocha & Chai to unit test ES6. - yer.ac | Adventures of a developer, and other things.","isPartOf":{"@id":"https:\/\/yer.ac\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#primaryimage"},"image":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#primaryimage"},"thumbnailUrl":"http:\/\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png","datePublished":"2019-04-08T19:48:24+00:00","dateModified":"2019-04-24T07:39:36+00:00","description":"Using Mocha and Chai to unit test ES6 Javascript in VS Code","breadcrumb":{"@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#primaryimage","url":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=604%2C244&ssl=1","contentUrl":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=604%2C244&ssl=1","width":604,"height":244},{"@type":"BreadcrumbList","@id":"https:\/\/yer.ac\/blog\/2019\/04\/08\/attempting-to-use-mocha-chai-to-unit-test-es6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/yer.ac\/blog\/"},{"@type":"ListItem","position":2,"name":"Attempting to use Mocha &#038; Chai to unit test ES6."}]},{"@type":"WebSite","@id":"https:\/\/yer.ac\/blog\/#website","url":"https:\/\/yer.ac\/blog\/","name":"yer.ac | Adventures of a developer, and other things.","description":"Blog to keep track of things I am upto","publisher":{"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/yer.ac\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d","name":"yer.ac","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","caption":"yer.ac"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paP5IW-17","jetpack-related-posts":[{"id":78,"url":"https:\/\/yer.ac\/blog\/2019\/04\/09\/debugging-es6-mocha-unit-tests-using-vs-code\/","url_meta":{"origin":69,"position":0},"title":"Debugging ES6 Mocha unit tests using VS Code","author":"yer.ac","date":"April 9, 2019","format":false,"excerpt":"The world of Mocha, VS Code and Node is still fairly new to me. Typically in the past all my JS unit tests have been debuggable in-browser using DevTools, but with Mocha this is not the case (As I am not deploying my spec files). I got Mocha to load\u2026","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/yer.ac\/blog\/category\/development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":599,"url":"https:\/\/yer.ac\/blog\/2026\/01\/23\/from-acceptance-criteria-to-playwright-tests-with-mcp\/","url_meta":{"origin":69,"position":1},"title":"From Acceptance Criteria to Playwright Tests with MCP","author":"yer.ac","date":"January 23, 2026","format":false,"excerpt":"Modern UI test tooling has quietly raised the bar for who can participate. Playwright is powerful, but it assumes comfort with TypeScript, selectors, repo structure, and terminal use. That gap often collapses testing back onto developers, creating pressure to almost validate their own work. This proof of concept explores using\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/yer.ac\/blog\/category\/development\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2026\/01\/cover.png?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2026\/01\/cover.png?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2026\/01\/cover.png?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2026\/01\/cover.png?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2026\/01\/cover.png?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":362,"url":"https:\/\/yer.ac\/blog\/2020\/02\/07\/%e2%9a%a1lightning-fast-testing-of-web-applications-with-cypress\/","url_meta":{"origin":69,"position":2},"title":"\u26a1lightning-fast testing of web applications with Cypress","author":"yer.ac","date":"February 7, 2020","format":false,"excerpt":"Cypress (Cypress.io) is an automation framework for web app testing built and configured with Javascript. Automated front-end testing is definitely not new, but Cypress really is something different. It's silly fast, requires almost no setup, has quick-to-learn syntax and has a really nice, feature packed test runner. Why Cypress? I'll\u2026","rel":"","context":"In &quot;Testing&quot;","block_context":{"text":"Testing","link":"https:\/\/yer.ac\/blog\/category\/testing\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/02\/image-6.png?fit=1089%2C402&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/02\/image-6.png?fit=1089%2C402&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/02\/image-6.png?fit=1089%2C402&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/02\/image-6.png?fit=1089%2C402&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/02\/image-6.png?fit=1089%2C402&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":315,"url":"https:\/\/yer.ac\/blog\/2019\/10\/16\/ensuring-dotnet-test-trx-coverage-files-end-up-in-sonarqube\/","url_meta":{"origin":69,"position":3},"title":"Ensuring &#8220;dotnet test&#8221; TRX &#038; Coverage files end up in SonarQube","author":"yer.ac","date":"October 16, 2019","format":false,"excerpt":"I have written before about using SonarQube to do static analysis, but one issue I never came back to was ensuring that code coverage files generated via a build pipeline end up being picked up by the Sonar Scanner to assess code coverage. Note that the following I am actually\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/yer.ac\/blog\/category\/devops\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/10\/image.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":576,"url":"https:\/\/yer.ac\/blog\/2025\/08\/18\/vibing-in-kiro-to-create-a-self-serve-portainer-wrapper\/","url_meta":{"origin":69,"position":4},"title":"Vibing in Kiro to create a self-serve Portainer wrapper.","author":"yer.ac","date":"August 18, 2025","format":false,"excerpt":"On a Friday afternoon with half an hour to spare, I tested Kiro, Amazon\u2019s new agentic IDE, against a real-world problem: giving my team a simple way to start and stop Docker services in Portainer. With nothing more than a rough prompt, a PowerShell script, and a few \u201cTrust command\u201d\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/yer.ac\/blog\/category\/development\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2025\/08\/Untitled-1.png?fit=1200%2C649&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2025\/08\/Untitled-1.png?fit=1200%2C649&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2025\/08\/Untitled-1.png?fit=1200%2C649&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2025\/08\/Untitled-1.png?fit=1200%2C649&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2025\/08\/Untitled-1.png?fit=1200%2C649&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":411,"url":"https:\/\/yer.ac\/blog\/2020\/02\/07\/supporting-multiple-configurations-in-cypress\/","url_meta":{"origin":69,"position":5},"title":"Supporting multiple configurations in Cypress","author":"yer.ac","date":"February 7, 2020","format":false,"excerpt":"By default, Cypress will support a single configuration based on the optional file cypress.json as described in their documentation here. Whilst this works fine for most, it would be great if we could have access to a cypress.dev.json for local development, or even better, a whole host of configuration files\u2026","rel":"","context":"In &quot;Testing&quot;","block_context":{"text":"Testing","link":"https:\/\/yer.ac\/blog\/category\/testing\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":10,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}