UNPKG

ember-cli-test-imagine-api

Version:

Create an Imaginary API in CoffeeScript with a declarative interface and neumonic for resources

70 lines (43 loc) 1.55 kB
# Ember-cli-test-imagine-api This is a testing library for creating a mock api using a declarative dsl. ## Installation * `ember install ember-cli-test-imagine-api` * edit ./tests/helpers/imagine-api.coffee ## Using Given that you modify './tests/helpers/imagine-api' to have a resource named 'blog_post' ``` Imagine.setApi( blog_article: "http://mysite.com/blog" ) ``` In your test case you would import the helper and then could establish data ``` `import imagine from '../helpers/imagine-api'` # set up a standard response for a post to "http://mysite.com/blog" # using the resource name as specified in helper/imagine-api.coffee imagine.json post: blog_article: status: 200 body: message: "ok" article: id: 1 name: "whut" $.ajax(type:"POST",contentType:'application/json',url: imagine.api.post).done((data)-> imagine.requestDataHistory('post','blog_article') # all the request bodies ever sent imagine.lastRequestData('post','blog_article') # request body of sent request imagine.callCount('post','blog_article') # number of times resource mock was triggered imagine.called('post','blog_article') # was it ever called? imagine.stop() # IMPORTANT - uninstall pretend-api handler ) ``` ## Running * `ember server` * Visit your app at http://localhost:4200. ## Running Tests * `ember test` * `ember test --server` ## Building * `ember build` For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).