What is a good method of storing JSON data/objects for development and unit testing with angular and jasmine?

I have seen some ways of accomplishing this. However, since I am new to unit testing with JavaScript, I fear going in a bad direction.

Here are some examples of what I'd like to accomplish:

  • Let's say I want to develop my site off a set of test data and and then later on plug it into a database. I figure it would be easier if I am developing and testing off of the same data to start. Maybe all I have to do is reference a js file which has a method in it for returning an array of that data. I don't know what setbacks that might have.
  • Another example would be that my initial reaction when trying to make a test that uses data was to simply make a $http call to my .json file. I quickly learned I can't do that and would have to mock the data. It seems a pain to have my data both in a unit-test mock as well as a .json file when the current purpose of the data is just for test/dev. I'll have to manage it in two places.
  • 1
  • I updated the question, attempting to narrow the scope. – Chris May 13 '14 at 19:34
  • 2
    It is still fairly broad and too open for discussion. – Adam Zuckerman May 13 '14 at 21:37
  • Your title says angular (often meaning "angular 2+"), but your tag says angularjs. You should clarify which you are using so that you get better input. – Caleb Apr 27 '18 at 7:21

If you start off with a spreadsheet, the process is easy:

  • Export the data as CSV
  • Transform the CSV to JSON
  • base64 Encode the JSON to reference it as a data:URI for HTTP tests

Once this is done, importing the data into your database is the last step.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.