1.13.1 • Published 9 years ago

ember-cli-test-imagine-api v1.13.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

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

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.