{"id":1635,"date":"2017-07-03T10:18:03","date_gmt":"2017-07-03T04:48:03","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=1635"},"modified":"2021-01-11T10:37:47","modified_gmt":"2021-01-11T05:07:47","slug":"test-rails-app-using-mocha-js-chai-js","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/","title":{"rendered":"How to Test Rails App using Mocha JS and Chai JS?"},"content":{"rendered":"\n<p>It has been quite some time since we started writing&nbsp;<a href=\"https:\/\/github.com\/rspec\/rspec-rails\" target=\"_blank\" rel=\"noopener noreferrer\">RSpecs<\/a>&nbsp;for our Rails applications. We had written tests for our rails&nbsp;<b>models<\/b>,&nbsp;<b>views<\/b> and&nbsp;<b>controllers<\/b>. So whole&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Model%E2%80%93view%E2%80%93controller\" target=\"_blank\" rel=\"noopener noreferrer\"><b>MVC<\/b><\/a>&nbsp;part was covered with tests.<\/p>\n\n\n\n<p>In the beginning we had very less JavaScript code in our applications but with the time passing by our app&#8217;s Javascript code increased exponentially. With more than&nbsp;<i>1000<\/i> Javascript functions, we started to feel we need tests for this since we cannot test all this manually.<\/p>\n\n\n\n<p>After digging many links and resources we found following popular Javascript testing frameworks which works with our rails app.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/jfirebaugh\/konacha\" target=\"_blank\" rel=\"noopener noreferrer\">Konacha<\/a>&nbsp;(<a href=\"https:\/\/mochajs.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mocha JS<\/a>&nbsp;and&nbsp;<a href=\"http:\/\/chaijs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Chai JS<\/a>)<\/li><li><a href=\"https:\/\/github.com\/jejacks0n\/teaspoon\" target=\"_blank\" rel=\"noopener noreferrer\">Teaspoon<\/a><\/li><\/ol>\n\n\n\n<p>We were amused by the syntax provided by konacha gem.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">expect(add(1, 2)).to.equal(3);<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"439\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/syntax-for-js.jpeg\" alt=\"syntax for js\" class=\"wp-image-13848\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/syntax-for-js.jpeg 442w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/syntax-for-js-300x298.jpeg 300w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/syntax-for-js-150x150.jpeg 150w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><figcaption>Sounds similar (The DeadPool style)!!<\/figcaption><\/figure><\/div>\n\n\n\n<p>This is very similar to our RSpec syntax. And since we were familiar to rspecs we decided to choose&nbsp;<b>konacha<\/b>&nbsp;gem as our alternative. So why to wait, let us start integrating this with our rails app.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to&nbsp;add?<\/h3>\n\n\n\n<p>We just need to add it to our gemfile<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">group :test, :development do\ngem 'konacha'\nend<\/pre>\n\n\n\n<p>Just do&nbsp;<code>$ bundle install<\/code>&nbsp;in your command line. And we are good to go!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How it can be&nbsp;used?<\/h3>\n\n\n\n<p>Now we need to create a directory named&nbsp;<code>javascripts<\/code>&nbsp;in our&nbsp;<code>spec<\/code>&nbsp;folder. The following command will take care of it!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mkdir spec\/javascripts<\/pre>\n\n\n\n<p>Any test files that we add in this folder must have&nbsp;<b>suffix<\/b> as&nbsp;<code>_spec<\/code>&nbsp;or&nbsp;<code>_tests<\/code>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Note: We can change the above suffix in the&nbsp;<code>config\/initializers\/konacha.rb<\/code>but I advise not to change that configuration and try to keep things simple&nbsp;\ud83d\ude42<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Life is really simple, but we insist on making it complicated&#8230; &#8211; Confucius<\/p><\/blockquote>\n\n\n\n<p>We can write our tests in Javascript(<code>.js<\/code>)or CoffeeScript(<code>.coffee<\/code>). Lets take a very simple Javascript example. Suppose you want to test the Javascript code written in file at&nbsp;<code>app\/assets\/javascripts\/calculator.js<\/code><\/p>\n\n\n\n<figure><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/b4c3f024d054d0c8ac4c3f5cbc46bb49.js\"><\/script>\n<figcaption><code>app\/assets\/javascripts\/calculator.js<\/code><\/figcaption>\n<\/figure>\n\n\n\n<p>Now we need to create spec file for&nbsp;<i>testing<\/i>&nbsp;these Javascript functions. Just create a file&nbsp;<code>spec\/javascripts\/calculator_spec.js<\/code>. It is not mandatory to use this naming convention but doing so will surely make things systematic.<\/p>\n\n\n\n<figure><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/54069f3af1d5f31afa10a4b12fda3212.js\"><\/script>\n<p>&nbsp;<\/p>\n<figcaption><code>spec\/javascripts\/calculator_spec.js<\/code><\/figcaption>\n<\/figure>\n\n\n\n<p>In above code&nbsp;<code>describe<\/code>&nbsp;and&nbsp;<code>it<\/code>&nbsp;block are analogous to RSpec blocks. Mocha JS provides&nbsp;<code>describe()<\/code>,&nbsp;<code>it()<\/code>,&nbsp;<code>before()<\/code>,&nbsp;<code>after()<\/code>,&nbsp;<code>beforeEach()<\/code>, and&nbsp;<code>afterEach()<\/code>&nbsp;blocks. Chai JS provides&nbsp;<code>expect<\/code> (<a href=\"http:\/\/chaijs.com\/guide\/styles\/#expect\" target=\"_blank\" rel=\"noopener noreferrer\">expectations<\/a>),&nbsp;<code>assert<\/code>(<a href=\"http:\/\/chaijs.com\/guide\/styles\/#assert\" target=\"_blank\" rel=\"noopener noreferrer\">assertions<\/a>) and&nbsp;<code>should<\/code>(<a href=\"http:\/\/chaijs.com\/guide\/styles\/#assert\" target=\"_blank\" rel=\"noopener noreferrer\">should<\/a>&nbsp;matchers).<\/p>\n\n\n\n<p>The very first line&nbsp;<code>\/\/= require calculator<\/code>&nbsp;in our&nbsp;<code>calculator_spec.js<\/code>&nbsp;adds the&nbsp;<code>app\/assets\/javascripts\/calculator.js<\/code>&nbsp;file in our spec, so it can be available for testing. You add as many Javascript files here. Generally we need to add multiple Javascript files in case if there is any dependency among them.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><i>Everything is ready to test. Perfect! Lets see them&nbsp;running!<\/i><\/p><\/blockquote>\n\n\n\n<p>We can run them either in console (command line) or in browser itself. Lets have a look at both these methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to run tests in&nbsp;browser?<\/h3>\n\n\n\n<p>Just a simple command and you are good to go!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ bundle exec rake konacha:serve<\/code><\/pre>\n\n\n\n<p>Now we can see our test running at\u00a0http:\/\/localhost:3500\u00a0. It will look like below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"614\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/mocha-chai-js.gif\" alt=\"Mocha JS and Chai JS\" class=\"wp-image-13849\"\/><figcaption>View tests in&nbsp;browser!<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">How to run tests from command&nbsp;line?<\/h3>\n\n\n\n<p>Now for doing this step we need to initialise few things. Create a file&nbsp;<code>config\/initializers\/konacha.rb<\/code>&nbsp;and paste in below contents.<\/p>\n\n\n\n<figure><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/ddc243ced2511ca87ea5fc30edea953f.js\"><\/script>\n<p>&nbsp;<\/p>\n<figcaption>config\/initializers\/konacha.rb<\/figcaption>\n<\/figure>\n\n\n\n<p>Here we tell konacha that spec directory is&nbsp;<code>spec\/javascripts<\/code>&nbsp;, also to find the spec files you need to match the files having&nbsp;<code>_spec<\/code>&nbsp;and&nbsp;<code>_test<\/code>&nbsp;in their filenames. We also need to specify web driver such as&nbsp;<code>:webkit<\/code>&nbsp;or&nbsp;<code>:selenium<\/code>or&nbsp;<code>:poltergeist<\/code>&nbsp;so it can run the test&nbsp;<a href=\"https:\/\/stackoverflow.com\/a\/4647740\/3815905\" target=\"_blank\" rel=\"noopener noreferrer\">headlessly<\/a>&nbsp;(<i>without GUI or console based<\/i>).<\/p>\n\n\n\n<p>Further we need to run the below command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ bundle exec rake konacha:run<\/code><\/pre>\n\n\n\n<p>You will see results like below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"426\" height=\"133\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Javascript-test.png\" alt=\"Javascript test\" class=\"wp-image-13850\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Javascript-test.png 426w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Javascript-test-300x94.png 300w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/><figcaption>Javascript test command line results<\/figcaption><\/figure>\n\n\n\n<p>Above screenshot shows there is one failed test and the rests are passed!<\/p>\n\n\n\n<p>We can also run individual specs by below command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ bundle exec rake konacha:run SPEC=individual_spec_file_path<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How can I test&nbsp;views?<\/h3>\n\n\n\n<p>If you have&nbsp;<i>JavaScript<\/i>&nbsp;templates such as&nbsp;<a href=\"http:\/\/www.embeddedjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">EJS<\/a>,&nbsp;<a href=\"http:\/\/handlebarsjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Handlebars<\/a>&nbsp;or <a href=\"https:\/\/mustache.github.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mustache JS<\/a>, then you can test your views with konacha. But if you are having your templates in ERB \/<a href=\"http:\/\/haml.info\/\" target=\"_blank\" rel=\"noopener noreferrer\">HAML<\/a>&nbsp;\/ <a href=\"http:\/\/slim-lang.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Slim<\/a>&nbsp;,then you need to convert it into a Javascript template. You need to do so because your ruby template may have instance variables and those variables are set from controllers. So this make it almost impossible to test. For testing ERB, HAML ruby view files we need to use&nbsp;<a href=\"https:\/\/github.com\/teamcapybara\/capybara\" target=\"_blank\" rel=\"noopener noreferrer\">capybara integration tests<\/a>&nbsp;or as a other alternative lets convert them into static templates.<\/p>\n\n\n\n<p>Lets convert our&nbsp;<code>erb<\/code>&nbsp;template into&nbsp;<code>ejs<\/code>&nbsp;template just by adding static values for testing purpose.<\/p>\n\n\n\n<p>First of all we need to add the gem&nbsp;<code>ejs<\/code>&nbsp;into our gemfile.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">group :development, :test do\ngem \"ejs\"\nend<\/pre>\n\n\n\n<p>As a best practice we must organise our templates at one common place. Lets create directory&nbsp;<code>spec\/javascripts\/templates<\/code>&nbsp;and add our all static templates there.<\/p>\n\n\n\n<figure><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/9f459d6dcc584a152eaf7c9309d73617.js\"><\/script><\/figure>\n\n\n\n<p>spec\/javascripts\/templates\/static_template.jst.ejs<\/p>\n\n\n\n<p>To make this available for our tests we must add following contents to file&nbsp;<code>spec\/javascripts\/spec_helper.js<\/code>&nbsp;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/= require_tree .\/templates<\/pre>\n\n\n\n<p>This will make all the templates available for testing!<\/p>\n\n\n\n<p>Now lets add the tests at&nbsp;<code>spec\/javascripts\/test_static_template_spec.js<\/code><\/p>\n\n\n\n<figure><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/65687415b7dc54256aab9f19ced7c31f.js\"><\/script>\n<p>&nbsp;<\/p>\n<figcaption>spec\/javascripts\/test_static_template_spec.js<\/figcaption>\n<\/figure>\n\n\n\n<p>In the first two lines we say add&nbsp;<code>jquery<\/code>&nbsp;and&nbsp;<code>spec_helper<\/code>&nbsp;file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">JST['templates\/&lt;*file_name*&gt;']()<\/pre>\n\n\n\n<p>It compiles the JST template to HTML view. And we replace the body with this JST view so we can mimic what we want to test. After the view is created we can just write our expectations and assertions.<\/p>\n\n\n\n<p>Now just run your tests they must pass now&nbsp;\ud83d\ude42 That&#8217;s it!<\/p>\n\n\n\n<p>Let me know which Javascript testing gems you use with your rails applications.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Which JS testing gem you use with Ruby on Rails applications? <a href=\"https:\/\/twitter.com\/hashtag\/rails?src=hash\">#rails<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/rubyonrails?src=hash\">#rubyonrails<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/javascript?src=hash\">#javascript<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/tests?src=hash\">#tests<\/a><\/p><p>&#8211; Ankur Vyas (@ankurvyas27) <a href=\"https:\/\/twitter.com\/ankurvyas27\/status\/881580249737306112\">July 2, 2017<\/a><\/p><\/blockquote>\n\n\n\n<p><script async=\"\" src=\"\/\/platform.twitter.com\/widgets.js\"><\/script><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Thanks for reading. If you liked it, press the heart button&nbsp;\ud83d\ude42<\/p><\/blockquote>\n\n\n\n<p>At BoTree we help individuals, startups and businesses build their ideas from Canvas to Cloud. We fix bugs for free, forever. We can help you with Support and Maintenance of existing applications not developed by us. We also provide 24 x 7 support to all our clients.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\"><strong><b>Click here for more<\/b> details&#8230;<\/strong><\/a><\/p>\n\n\n\n<p>At<a href=\"https:\/\/www.botreetechnologies.com\/\"> BoTree Technologies<\/a>, we build enterprise applications with our RoR team of 25+ engineers.<\/p>\n\n\n\n<p>We also specialize in Python, RPA, AI, Django, JavaScript and ReactJS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>It has been quite some time since we started writing&nbsp;RSpecs&nbsp;for&#8230;<\/p>\n","protected":false},"author":9,"featured_media":13847,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-1635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Test Rails App using Mocha JS and Chai JS?<\/title>\n<meta name=\"description\" content=\"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.\" \/>\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.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Test Rails App using Mocha JS and Chai JS?\" \/>\n<meta property=\"og:description\" content=\"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-03T04:48:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-11T05:07:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ankur Vyas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ankur Vyas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\"},\"author\":{\"name\":\"Ankur Vyas\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\"},\"headline\":\"How to Test Rails App using Mocha JS and Chai JS?\",\"datePublished\":\"2017-07-03T04:48:03+00:00\",\"dateModified\":\"2021-01-11T05:07:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\"},\"wordCount\":1059,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\",\"name\":\"How to Test Rails App using Mocha JS and Chai JS?\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg\",\"datePublished\":\"2017-07-03T04:48:03+00:00\",\"dateModified\":\"2021-01-11T05:07:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\"},\"description\":\"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg\",\"width\":1920,\"height\":1280,\"caption\":\"Test Rails App using Mocha JS and Chai JS\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Test Rails App using Mocha JS and Chai JS?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\",\"name\":\"Ankur Vyas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"caption\":\"Ankur Vyas\"},\"description\":\"Ankur is a Ruby on Rails Developer and Practice Lead JavaScript. He loves Ruby, JavaScript, reading and writing blogs, problem-solving and taking ownership of work. Apart from coding he likes to listen to songs, gaming and traveling.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Test Rails App using Mocha JS and Chai JS?","description":"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.","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.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Test Rails App using Mocha JS and Chai JS?","og_description":"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.","og_url":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2017-07-03T04:48:03+00:00","article_modified_time":"2021-01-11T05:07:47+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg","type":"image\/jpeg"}],"author":"Ankur Vyas","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Ankur Vyas","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/"},"author":{"name":"Ankur Vyas","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5"},"headline":"How to Test Rails App using Mocha JS and Chai JS?","datePublished":"2017-07-03T04:48:03+00:00","dateModified":"2021-01-11T05:07:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/"},"wordCount":1059,"commentCount":0,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/","url":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/","name":"How to Test Rails App using Mocha JS and Chai JS?","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg","datePublished":"2017-07-03T04:48:03+00:00","dateModified":"2021-01-11T05:07:47+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5"},"description":"Learn more about how to test rails app using mocha js and chai js? It has been quite some time since we started writing RSpecs for our Rails applications.","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/ruby-on-rails-mocha-chai.jpg","width":1920,"height":1280,"caption":"Test Rails App using Mocha JS and Chai JS"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/test-rails-app-using-mocha-js-chai-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Test Rails App using Mocha JS and Chai JS?"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5","name":"Ankur Vyas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","caption":"Ankur Vyas"},"description":"Ankur is a Ruby on Rails Developer and Practice Lead JavaScript. He loves Ruby, JavaScript, reading and writing blogs, problem-solving and taking ownership of work. Apart from coding he likes to listen to songs, gaming and traveling."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=1635"}],"version-history":[{"count":2,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1635\/revisions"}],"predecessor-version":[{"id":14895,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1635\/revisions\/14895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13847"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=1635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=1635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=1635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}