Setting up Trek's Pretender for Demo / Development

I know this seems simplistic but I don’t see in the README for pretender where we are supposed to put our mock server code. Basically, where do we put the code below in an Ember-cli app?

var PHOTOS = {
  "10": {
    id: 10,
    src: ''
  "42": {
    id: 42,
    src: ''

var server = new Pretender(function(){
  this.get('/photos', function(request){
    var all =  JSON.stringify(Object.keys(PHOTOS).map(function(k){return PHOTOS[k]}))
    return [200, {"Content-Type": "application/json"}, all]

  this.get('/photos/:id', function(request){
    return [200, {"Content-Type": "application/json"}, JSON.stringify(PHOTOS[])]

I want to run the mock server for development and demo purposes not just for testing. I know I am missing something simple but I do not see any explanation on how to do this.

1 Like

+1. I’m using ember-cli-pretender and can’t find very much information on how to setup it up (where to place the server config, etc.). Any help would be much appreciated.

1 Like

@brendanoh, @BradWheel Did you ever figure out a good way to do this?

How is that different from the http-mock in ember-cli?

Just guessing here but I think part of the difference is that Pretender intercepts your API calls. Where as a http-mock is really just an express server setup to run as your stubbed API so doing real AJAX behind the scenes. End effect is mostly the same. But the Pretender stuff is typically more tightly coupled to test cases such as integration tests testing very specific models and pages.

With http-mock it seems like you could build out a more extensive virtual API layer if you were so inclined.

For full on demo I personally would use http-mock. But write my tests with Pretender.