Cause
require method is available only on the server side (Nodejs / PhantomJS), but all jasmine tests (specs) are run on the client side.
Possible Solution
You can create a JavaScript file in the helpers folder with the following contents:
window.jsonFile = { some : json_object }
And use the jsonFile link in your spec files.
Description
From the PhantomJS description:
PhantomJS is a mute WebKit script with a JavaScript API.
From grunt-contrib-jasmine description:
Run jasmine specs silently through PhantomJS.
grunt-contrib-jasmine automatically creates the _SpecRunner.html file (see below, for example) with all user specifications and passes it to PhantomJS. PhantomJS is a separate executable file that in Nodejs is only wrapped as a package. This is the same executable file as downloaded from Phantomjs.org .
At the end, this line is executed:. .\node_modules\grunt-contrib-jasmine\node_modules\grunt-lib-phantomjs\node_modules\phantomjs\lib\phantom\phantomjs .\node_modules\grunt-contrib-jasmine\node_modules\grunt-lib-phantomjs\phantomjs\main.js .\_SpecRunner.html . Here, the main.js file should open the page and link the alerts ( alert(jsonString) ) that are thrown into the grunt log.
So, the PhantomJS API is available in main.js , but not in the _SpecRunner.html and jasmine spec files.
The result will be the same as if it was opened by _SpecRunner.html with a browser, except that all messages will be intercepted by the jasmine reporter and displayed on the screen.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Jasmine Spec Runner</title> <link rel="stylesheet" type="text/css" href=".grunt/grunt-contrib-jasmine/jasmine.css"> <script src="./.grunt/grunt-contrib-jasmine/jasmine.js"></script> <script src="./.grunt/grunt-contrib-jasmine/jasmine-html.js"></script> <script src="./test/vendor/jquery.js"></script> <script src="./test/helpers/ts.js"></script> <script src="./test/main_spec.js"></script> <script src="./.grunt/grunt-contrib-jasmine/reporter.js"></script> <script src="./.grunt/grunt-contrib-jasmine/jasmine-helper.js"></script> </head> <body> </body> </html>