{"id":251,"date":"2012-11-23T14:42:00","date_gmt":"2012-11-23T14:42:00","guid":{"rendered":"https:\/\/www.simplybusiness.co.uk\/javascript-is-difficult-to-test\/"},"modified":"2024-05-29T18:39:59","modified_gmt":"2024-05-29T18:39:59","slug":"javascript-is-difficult-to-test","status":"publish","type":"post","link":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test","title":{"rendered":"JavaScript is difficult to test?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Well that is what I thought, until someone introduced me to Jasmine, no not Aladdin&#8217;s girlfriend, the&nbsp;<a href=\"http:\/\/pivotal.github.com\/jasmine\/\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"noopener noreferrer\" target=\"_blank\">Jasmine Testing Framework<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"576\" src=\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?w=768\" alt=\"jasmine\" class=\"wp-image-9602\" srcset=\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp 768w, https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?resize=150,113 150w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Intro<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Firstly, I&#8217;m no JavaScript guru, my knowledge level is VERY basic. I do work with JavaScript and jQuery, but previously have not really tried to write tests for it. Instead I have usually copied code from an example I found online; poked at it until it did what I wanted and then never looked at it again. But not this time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our company is relatively new to agile processes (2 years&#8217;ish) and we are doing great with BDD on the Ruby side of things, but we currently don&#8217;t have any tests for our JavaScript. So as some JavaScript work needed doing we decided to try to write some tests using jasmine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post I won&#8217;t cover setting up jasmine, there are a number of tutorials around that do this. I used&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"http:\/\/net.tutsplus.com\/tutorials\/JavaScript-ajax\/testing-your-JavaScript-with-jasmine\/\" rel=\"noopener noreferrer\" target=\"_blank\">this<\/a>&nbsp;and&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"http:\/\/evanhahn.com\/?p=181\" rel=\"noopener noreferrer\" target=\"_blank\">this<\/a>&nbsp;which showed me how to set up a standalone version which comes with a few tests. I won&#8217;t cover how jQuery&#8217;s autocomplete works as this is covered on their site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead I want to talk about what I needed to test and how I had to change our code to make it testable.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.tech.sb\/\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"noopener noreferrer\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"256\" src=\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/sb-tech-site-technology.webp?w=768\" alt=\"sb-tech-site-technology\" class=\"wp-image-9605\" srcset=\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/sb-tech-site-technology.webp 768w, https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/sb-tech-site-technology.webp?resize=150,50 150w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The Problem<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We have a trade selector that uses jQuery&#8217;s autocomplete. This takes an array of objects to supply the data for the autocomplete dropdown as well as a parameter used when we redirect after a trade is selected.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9de2612d93ae2f5a3812df83bcd65780\" style=\"border-style:none;border-width:0px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>var trades = &#091;\n  {trade:'Accident investigator', categorycode:'1'},\n    {trade:'Accountant',            categorycode:'2'},\n    {trade:'Baker',                 categorycode:'3'}\n    ]\n\n$(\"#trade_selector\").autocomplete(trades, {\n  matchContains: \"trade\",\n    formatItem: function(item) {\n      return item.trade;\n    }\n  }).result(function(event, item) {\n  location.href = 'http:\/\/some.site.for.business\/1.htm?category=' + item.categorycode;\n  });<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I was given a task of updating this so that the redirect was conditional based on the trade selected. e.g. the Accountant should still redirect to some.site.for.business, but a Baker should redirect to some.site.for.shop. But I wanted to do this test driven.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My first problem was I had no way to cleanly hook into the code and with my lack of understanding of how JavaScript events and inline functions worked the task seemed immense. So I started chipping.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My thought was that I don&#8217;t need to test &#8216;autocomplete&#8217; as that is &#8216;hopefully&#8217; tested by the makers of jQuery. I also didn&#8217;t need to test that the correct item was being passed to the &#8216;result&#8217; function as that was working already. What I really wanted to test was the function that was being called from the &#8216;results&#8217; function. So my first change wasn&#8217;t exactly TDD but it opened a crack to let me in:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-214f267fe6c1cdfc7e23fbfe5de1a2e6\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>var redirectOnTrade(event, item){\n  location.href = 'http:\/\/some.site.for.business\/1.htm?category=' + item.categorycode;\n}\n\n$(\"#trade_selector\").autocomplete(trades, {\n  matchContains: \"trade\",\n\n    formatItem: function(item) {\n      return item.trade;\n    }\n}).result(redirectOnTrade);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allowed me to write my first test in my AutocompleteSpec.js file:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8f28d19a13cd839461c1cdcfdb559447\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>describe('should redirect on selecting a trade', function() {\n  var businessTradeItem;\n\n    beforeEach(function (){\n      businessTradeItem = {trade: 'Foo', categorycode: 1 };\n    });\n\ndescribe('redirecting to business', function() {\n\n  it('a business trade should redirect correctly to business', function() {\n      redirectOnTrade('', businessTradeItem);\n        expect(location.href).toHaveBeenCalledWith('http:\/\/some.site.for.business\/1.htm?category=1');\n    });\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Great I had a test and it passed. Right? Wrong! As I was trying to make expectations on location.href (not a function) Jasmine was not able to check expectations and each time I called the test my Jasmine SpecRunner.html would change location to my redirected page. Doh! So my second change was to add another function:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-355541e8d052792e3c1dfa1f1e3446db\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>var changeLocation(url){\n  location.href = url\n}\n\nvar redirectOnTrade(event, item){\n  changeLocation('http:\/\/some.site.for.business\/1.htm?category=' + item.categorycode);\n}\n\n$(\"#trade_selector\").autocomplete(trades, {\n  matchContains: \"trade\",\n\n    formatItem: function(item) {\n      return item.trade;\n    }\n}).result(redirectOnTrade);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Again, it does mean that all I&#8217;m doing is wrapping up functionality into discreet functions but it did allow me to change my tests like so:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8d37aa0b1a2b8df9e52947e9f7ebd48b\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>describe('should redirect on selecting a trade', function() {\n  var businessTradeItem;\n\n    beforeEach(function (){\n      businessTradeItem = {trade: 'Foo', categorycode: 1 };\n        spyOn(window, 'changeLocation');\n    });\n\n    describe('redirecting to business', function() {\n      it('a business trade should redirect correctly to business', function() {\n          redirectOnTrade('', businessTradeItem);\n            expect(window.changeLocation).toHaveBeenCalledWith('http:\/\/some.site.for.business\/1.htm?category=1');\n        });\n    });\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now I had a valid test and could get on with writing some failing tests. So here is my first:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d9d8fd869213d4e4f269b5ff9723c6f7\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>describe('should redirect on selecting a trade', function() {\n  var businessTradeItem;\n\n    beforeEach(function (){\n      businessTradeItem = {trade: 'Foo', categorycode: 1, site: 'business' };\n        shopTradeItem =     {trade: 'Boo', categorycode: 2, site: 'shop' };\n\n        spyOn(window, 'changeLocation');\n    });\n\n    describe('redirecting to business', function() {\n      it('a business trade should redirect correctly to business', function() {\n          redirectOnTrade('', businessTradeItem);\n            expect(window.changeLocation).toHaveBeenCalledWith('http:\/\/some.site.for.business\/1.htm?category=1');\n        });\n\n      it('a shop trade should redirect correctly to shop', function() {\n          redirectOnTrade('', shopTradeItem);\n            expect(window.changeLocation).toHaveBeenCalledWith('http:\/\/some.site.for.shop\/1.htm?category=2');\n        });\n    });\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So now I could finally get on and implement my new redirect code:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-877c7b990d0a2e21c654fde04704bfb0\" style=\"border-width:1px;border-radius:10px;padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--30)\"><code>var trades = &#091;\n  {trade:'Accident investigator', categorycode:'1', site: 'business' },\n    {trade:'Accountant',            categorycode:'2', site: 'business' },\n    {trade:'Baker',                 categorycode:'3', site: 'shop' }\n]\n\nvar changeLocation(url){\n  location.href = url\n}\n\nvar redirectOnTrade(event, item){\n\nif( item.site === 'business' ){\nchangeLocation('&lt;http:\/\/some.site.for.business\/1.htm?category=&gt;' + item.categorycode);\n} else {\nchangeLocation('&lt;http:\/\/some.site.for.shop\/1.htm?category=&gt;' + item.categorycode);\n}\n}\n\n$(\"#trade_selector\").autocomplete(trades, {\n  matchContains: \"trade\",\n\n    formatItem: function(item) {\n      return item.trade;\n    }\n}).result(redirectOnTrade);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And both my tests pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now I am only showing you a part of the real code and a fraction of the full trade list and there was still a whole load of refactoring to be done but by the time I had finished I had over 800 specs surrounding this code, but I think this illustrates the point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Jasmine made writing the tests easy and very RSpec like, but your code (even JavaScript) needs to be written for testability. Wrapping up your JavaScript into small discreet functions instead of a large inline set of functions, makes it a lot easier to test your code in isolation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I used to think JavaScript is difficult to test? Not any more \ud83d\ude42<\/p>\n\n\n\n<div class=\"wp-block-group alignwide has-azure-200-background-color has-background has-global-padding is-layout-constrained wp-container-core-group-is-layout-94e519ba wp-block-group-is-layout-constrained\" style=\"padding-top:var(--wp--preset--spacing--80);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--80);padding-left:var(--wp--preset--spacing--40)\">\n<h3 class=\"wp-block-heading has-text-align-center\">Ready to start your career at Simply Business?<\/h3>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\">Want to know more about what it&#8217;s like to work in tech at Simply Business? Read about our approach to tech, then check out our current vacancies.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-a89b3969 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size has-medium-font-size\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.simplybusiness.co.uk\/about-us\/careers\/tech\/\">Find out more<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div id=\"newsletter-subscribe\" class=\"wp-block-group newsletter-subscribe is-layout-flow wp-block-group-is-layout-flow\" style=\"border-top-color:#cccccc;border-top-width:1px;padding-top:var(--wp--preset--spacing--80);padding-right:0;padding-bottom:var(--wp--preset--spacing--80);padding-left:0\">\n<p class=\"has-text-align-center has-dark-800-color has-text-color has-link-color has-medium-font-size wp-elements-3f9fd1b23ae58c66d5a95fbc7e773846 wp-block-paragraph\" style=\"margin-bottom:var(--wp--preset--spacing--50)\">Keep up to date with Simply Business. Subscribe to our monthly newsletter and follow us on social media.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-222c5d1d wp-block-buttons-is-layout-flex\" style=\"margin-bottom:var(--wp--preset--spacing--50)\">\n<div class=\"wp-block-button is-style-outline has-size-medium is-style-outline--1\"><a class=\"wp-block-button__link wp-element-button\" href=\"\/about-us\/newsletter-signup\">Subscribe to our newsletter<\/a><\/div>\n<\/div>\n\n\n\n<ul class=\"wp-block-social-links has-small-icon-size is-style-logos-only is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-a89b3969 wp-block-social-links-is-layout-flex\"><li class=\"wp-social-link wp-social-link-facebook  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.facebook.com\/simplybusiness\" class=\"wp-block-social-link-anchor\" rel=\"noopener noreferrer\" target=\"_blank\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z\"><\/path><\/svg><span class=\"wp-block-social-link-label screen-reader-text\">Follow Simply Business on Facebook<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-x  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.x.com\/simplybusiness\" class=\"wp-block-social-link-anchor\" rel=\"noopener noreferrer\" target=\"_blank\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z\" \/><\/svg><span class=\"wp-block-social-link-label screen-reader-text\">Follow Simply Business on X<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-youtube  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.youtube.com\/user\/simplybusiness\" class=\"wp-block-social-link-anchor\" rel=\"noopener noreferrer\" target=\"_blank\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z\"><\/path><\/svg><span class=\"wp-block-social-link-label screen-reader-text\">Subscribe to Simply Business Videos on Youtube<\/span><\/a><\/li>\n\n<li class=\"wp-social-link wp-social-link-linkedin  wp-block-social-link\"><a rel=\"noopener nofollow\" target=\"_blank\" href=\"https:\/\/www.linkedin.com\/company\/simply-business_39914\" class=\"wp-block-social-link-anchor\" rel=\"noopener noreferrer\" target=\"_blank\"><svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z\"><\/path><\/svg><span class=\"wp-block-social-link-label screen-reader-text\">Follow Simply Business on LinkedIn<\/span><\/a><\/li><\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Well that is what I thought, until someone introduced me to Jasmine, no not Aladdin&#8217;s girlfriend, the&nbsp;Jasmine Testing Framework. Intro Firstly, I&#8217;m no JavaScript guru, my knowledge level is VERY basic. I do work with JavaScript and jQuery, but previously have not really tried to write tests for it. Instead I have usually copied code [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sb_hreflang":"","sb_hreflang_url":"","disable_breadcrumbs":false,"sb_breadcrumbs":[],"footnotes":""},"tags":[],"hidden-category":[],"coauthors":[216],"class_list":["post-251","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript is difficult to test?<\/title>\n<meta name=\"description\" content=\"JavaScript is difficult to test? | Simply Business\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript is difficult to test?\" \/>\n<meta property=\"og:description\" content=\"JavaScript is difficult to test? | Simply Business\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\" \/>\n<meta property=\"og:site_name\" content=\"Simply Business UK\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/simplybusiness\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-23T14:42:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-29T18:39:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/06\/sb-opengraph.png\" \/>\n<meta name=\"author\" content=\"Christopher Chamberlain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@simplybusiness\" \/>\n<meta name=\"twitter:site\" content=\"@simplybusiness\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christopher Chamberlain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\"},\"author\":{\"@type\":\"Person\",\"name\":\"Christopher Chamberlain\",\"description\":\"\"},\"headline\":\"JavaScript is difficult to test?\",\"datePublished\":\"2012-11-23T14:42:00+00:00\",\"dateModified\":\"2024-05-29T18:39:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\"},\"wordCount\":738,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?w=768\",\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\",\"url\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\",\"name\":\"JavaScript is difficult to test?\",\"isPartOf\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?w=768\",\"datePublished\":\"2012-11-23T14:42:00+00:00\",\"dateModified\":\"2024-05-29T18:39:59+00:00\",\"description\":\"JavaScript is difficult to test? | Simply Business\",\"breadcrumb\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage\",\"url\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp\",\"contentUrl\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp\",\"width\":768,\"height\":576,\"caption\":\"jasmine\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.simplybusiness.co.uk\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript is difficult to test?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/#website\",\"url\":\"https:\/\/www.simplybusiness.co.uk\/\",\"name\":\"Simply Business UK\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.simplybusiness.co.uk\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.simplybusiness.co.uk\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/#\/schema\/person\/4a0051d581e10bddeb00487aaa80d76a\",\"name\":\"hiteshpatel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp9df6147f02078f0218660330fdfbacf3\",\"url\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp\",\"contentUrl\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp\",\"caption\":\"hiteshpatel\"}},{\"@type\":\"PostalAddress\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#local-main-place-address\",\"streetAddress\":\"Hylo, 105 Bunhill Row\",\"addressLocality\":\"London\",\"postalCode\":\"EC1Y 8LZ\",\"addressCountry\":\"GB\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#local-main-organization-logo\",\"url\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/logo.png\",\"contentUrl\":\"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/logo.png\",\"width\":533,\"height\":187,\"caption\":\"Simply Business UK\"}]}<\/script>\n<meta name=\"geo.placename\" content=\"London\" \/>\n<meta name=\"geo.region\" content=\"United Kingdom (UK)\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript is difficult to test?","description":"JavaScript is difficult to test? | Simply Business","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:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/","og_locale":"en_GB","og_type":"article","og_title":"JavaScript is difficult to test?","og_description":"JavaScript is difficult to test? | Simply Business","og_url":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/","og_site_name":"Simply Business UK","article_publisher":"https:\/\/www.facebook.com\/simplybusiness","article_published_time":"2012-11-23T14:42:00+00:00","article_modified_time":"2024-05-29T18:39:59+00:00","og_image":[{"url":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/06\/sb-opengraph.png","type":"","width":"","height":""}],"author":"Christopher Chamberlain","twitter_card":"summary_large_image","twitter_creator":"@simplybusiness","twitter_site":"@simplybusiness","twitter_misc":{"Written by":"Christopher Chamberlain","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#article","isPartOf":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/"},"author":{"@type":"Person","name":"Christopher Chamberlain","description":""},"headline":"JavaScript is difficult to test?","datePublished":"2012-11-23T14:42:00+00:00","dateModified":"2024-05-29T18:39:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/"},"wordCount":738,"commentCount":0,"publisher":{"@id":"https:\/\/www.simplybusiness.co.uk\/#organization"},"image":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?w=768","inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/","url":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/","name":"JavaScript is difficult to test?","isPartOf":{"@id":"https:\/\/www.simplybusiness.co.uk\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage"},"image":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp?w=768","datePublished":"2012-11-23T14:42:00+00:00","dateModified":"2024-05-29T18:39:59+00:00","description":"JavaScript is difficult to test? | Simply Business","breadcrumb":{"@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#primaryimage","url":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp","contentUrl":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/jasmine.webp","width":768,"height":576,"caption":"jasmine"},{"@type":"BreadcrumbList","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.simplybusiness.co.uk\/"},{"@type":"ListItem","position":2,"name":"JavaScript is difficult to test?"}]},{"@type":"WebSite","@id":"https:\/\/www.simplybusiness.co.uk\/#website","url":"https:\/\/www.simplybusiness.co.uk\/","name":"Simply Business UK","description":"","publisher":{"@id":"https:\/\/www.simplybusiness.co.uk\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.simplybusiness.co.uk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.simplybusiness.co.uk\/#\/schema\/person\/4a0051d581e10bddeb00487aaa80d76a","name":"hiteshpatel","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp9df6147f02078f0218660330fdfbacf3","url":"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp","contentUrl":"https:\/\/www.simplybusiness.co.uk\/wp-content\/themes\/simply-business\/dist\/images\/default-author-avatar.webp","caption":"hiteshpatel"}},{"@type":"PostalAddress","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#local-main-place-address","streetAddress":"Hylo, 105 Bunhill Row","addressLocality":"London","postalCode":"EC1Y 8LZ","addressCountry":"GB"},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test\/#local-main-organization-logo","url":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/logo.png","contentUrl":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/05\/logo.png","width":533,"height":187,"caption":"Simply Business UK"}]},"geo.placename":"London","geo.region":"United Kingdom (UK)"},"parsely":{"version":"1.1.0","canonical_url":"https:\/\/simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test","smart_links":{"inbound":0,"outbound":0},"traffic_boost_suggestions_count":0,"meta":{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"JavaScript is difficult to test?","url":"http:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test","mainEntityOfPage":{"@type":"WebPage","@id":"http:\/\/www.simplybusiness.co.uk\/about-us\/tech\/2012\/11\/javascript-is-difficult-to-test"},"thumbnailUrl":"","image":{"@type":"ImageObject","url":""},"articleSection":"Uncategorised","author":[{"@type":"Person","name":"Christopher Chamberlain"}],"creator":["Christopher Chamberlain"],"publisher":{"@type":"Organization","name":"Simply Business UK","logo":"https:\/\/www.simplybusiness.co.uk\/wp-content\/uploads\/sites\/3\/2024\/04\/icon-512x512-1.png"},"keywords":[],"dateCreated":"2012-11-23T14:42:00Z","datePublished":"2012-11-23T14:42:00Z","dateModified":"2024-05-29T18:39:59Z"},"rendered":"<script type=\"application\/ld+json\" class=\"wp-parsely-metadata\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@type\":\"NewsArticle\",\"headline\":\"JavaScript is difficult to test?\",\"url\":\"http:\\\/\\\/www.simplybusiness.co.uk\\\/about-us\\\/tech\\\/2012\\\/11\\\/javascript-is-difficult-to-test\",\"mainEntityOfPage\":{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.simplybusiness.co.uk\\\/about-us\\\/tech\\\/2012\\\/11\\\/javascript-is-difficult-to-test\"},\"thumbnailUrl\":\"\",\"image\":{\"@type\":\"ImageObject\",\"url\":\"\"},\"articleSection\":\"Uncategorised\",\"author\":[{\"@type\":\"Person\",\"name\":\"Christopher Chamberlain\"}],\"creator\":[\"Christopher Chamberlain\"],\"publisher\":{\"@type\":\"Organization\",\"name\":\"Simply Business UK\",\"logo\":\"https:\\\/\\\/www.simplybusiness.co.uk\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2024\\\/04\\\/icon-512x512-1.png\"},\"keywords\":[],\"dateCreated\":\"2012-11-23T14:42:00Z\",\"datePublished\":\"2012-11-23T14:42:00Z\",\"dateModified\":\"2024-05-29T18:39:59Z\"}<\/script>","tracker_url":"https:\/\/cdn.parsely.com\/keys\/simplybusiness.co.uk\/p.js"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":13,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":13716,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/posts\/251\/revisions\/13716"}],"wp:attachment":[{"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/tags?post=251"},{"taxonomy":"hidden-category","embeddable":true,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/hidden-category?post=251"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.simplybusiness.co.uk\/wp-json\/wp\/v2\/coauthors?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}