{"id":308,"date":"2022-08-30T14:59:11","date_gmt":"2022-08-30T14:59:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/10\/13\/why-do-these-resharper-jasmine-tests-run-in-browser-but-not-in-phantomjs-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:59:11","modified_gmt":"2022-08-30T14:59:11","slug":"why-do-these-resharper-jasmine-tests-run-in-browser-but-not-in-phantomjs-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/why-do-these-resharper-jasmine-tests-run-in-browser-but-not-in-phantomjs-record-and-share-programming-errors\/","title":{"rendered":"Why do these resharper Jasmine tests run in browser but not in phantomjs-Record and share programming errors"},"content":{"rendered":"<p>Thank you in advance to everyone that reads through this &#8211; there&#8217;s quite a lot of detail to the question.<\/p>\n<p>I am trying to introduce javascript testing into our project using Jasmine. The tests I&#8217;ve written work in the browser but not using PhantomJS via Resharper.<\/p>\n<p>I&#8217;m guessing I&#8217;m missing something about the plumbing required to parse our JS files (maybe I&#8217;m identifying a problem with our JS setup). Any help hugely appreciated&#8230;<\/p>\n<p>I have setup Jasmine tests inside Visual Studio using jasmine&#8230;<\/p>\n<pre><code>\/\/ The Jasmine Test Framework\n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/ Classes to test\n\/\/\/ \n\ndescribe(\"Breadcrumbs\", function () {\n    it(\"should have a window object\", function() {\n        \/\/this test passes in PhantomJS and the browser\n        expect(window).toBeDefined();\n    });\n\n    it(\"should have the base object available\", function() {\n        \/\/this test only passes in the browser\n        expect(window.MyNamespace).toBeDefined();\n    });\n});\n<\/code><\/pre>\n<p>this references a JS file which contains&#8230;<\/p>\n<pre><code>(function (app, $, undefined) {\n     \/\/do things here\n}(window.MyNameSpace = window.MyNamespace || {}, jQuery));\n<\/code><\/pre>\n<p>I have a SpecRunner.html which can successfully run my tests&#8230; it&#8217;s the specrunner html that comes with Jasmine 1.3.1 standalone with the head edited like so&#8230;<\/p>\n<pre><code> \n  \n  \n  \n\n  \n  \n\n  \n  \n<\/code><\/pre>\n<p>These tests are being run either by my SpecRunner.html (which works fine) or through Resharper 7s testrunner using PhantomJS which I&#8217;m guessing is not evaluating the code in my JS code file..?<\/p>\n<p>Update: some extra details&#8230;<\/p>\n<p>Resharper version is:<\/p>\n<blockquote>\n<p>JetBrains ReSharper 7.1.3 Full Edition Build 7.1.3000.2254 on 2013-04-10T16:48:18<\/p>\n<\/blockquote>\n<p>and Phantom JS version is 1.9.1.0<\/p>\n<p>And I&#8217;ve just realised I don&#8217;t have the actual error in my question &#8211; Doh!<\/p>\n<pre><code>TypeError: 'undefined' is not an object (evaluating 'window.MyNamespace.Whatever') in http:\/\/localhost:47815\/Tests.js (line 26)\nTypeError: 'undefined' is not an object (evaluating 'window.MyNamespace.Whatever')\n    at  BreadcrumbsSpec.js: line 26\n    at  jasmine.js: line 1035\n    at  jasmine.js: line 2053\n    at  jasmine.js: line 2006\n    at  jasmine.js: line 2335\n    at  jasmine.js: line 2053\n    at  jasmine.js:2043\n<\/code><\/pre>\n<p>Interestingly Tests.js is not my file &#8211; I guess that&#8217;s a R# thing.<\/p>\n<p>Ah &#8211; Tests.js is my spec file (i.e. BreadcrumbsSpec.js in this instance). If I launch switch options to tell the Resharper TestRunner to use a browser I get the same results (i.e. only window is defined) and a blank page in the browser&#8230;<\/p>\n<ol>\n<li>\n<p>Eureka&#8230; the problem was an ID-ten-T otherwise known as PEBCAK<\/p>\n<p>I hadn&#8217;t thought about or investigated how R# was actually going to run the tests. And so had set the reference paths in the Spec.js relative to <em>my<\/em> specrunner.html<\/p>\n<p>R# actually injects the Spec file into an html page as an inline script so my relative paths were all wrong.<\/p>\n<p>I simply set the reference paths as absolute from the project root and all was fine.<\/p>\n<pre><code>\/\/ The Jasmine Test Framework\n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/\/ \n\/\/ Classes to test\n\/\/\/ \n<\/code><\/pre>\n<p>Thanks to R# people for engaging with me on Twitter!<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-10-13 02:32:57. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Thank you in advance to everyone that reads through this &#8211; there&#8217;s quite a lot of detail to the question. I am trying to introduce javascript testing into our project using Jasmine. The tests I&#8217;ve written work in the browser but not using PhantomJS via Resharper. I&#8217;m guessing I&#8217;m missing something about the plumbing required [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-308","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}