Testing emberjs apps is the current buzzing topic. Here I try out my way to stub network calls while doing emberjs integration tests.
Here I would like to try out dyson. Its a nodejs app with simple DSL. Though it has its fake data generator dyson-generators, but I find that it has limited generators. So, for fake data generation, we’ll be using Faker which has massive amounts of fake contextual data.
Lets whip up one for our next ambitious fake API.
Clone the repo
We’ll use the dyson-demo repo for our own api.
git clone firstname.lastname@example.org:webpro/dyson-demo.git articles-api cd articles-api npm install npm install Faker --save echo 'node_modules/' > .gitignore git add .gitignore git commit -m 'node_modules folder git ignored'
Start the server with
It starts the server on port
3000 by default, which can be customized in file
http:localhost/3000 to list the stubbed endpoints.
You will see some demo end points which you can wipe it out or keep.
Setup our API endpoint
Here, we will use
Article as our example resource.
To list the articles end point in the browser, first we’ll have to make an entry in the file
1 2 3 4 5
Now we have to add a template for
articles. Create the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
For dyson to pick up the changes, we should re-start the server.
Then if we click the
/articles or visit
http://localhost:3000/articles, the output should look like the following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
So, now we got our api that responds to
/articles. To get better understanding of
dyson, you can look out the examples that it already exists in the repo.
You can also see the README of Faker.js to find various fake data generators.
I’ve pushed the repo at https://github.com/millisami/articles-api for future reference.
In the next part, we’ll write an Ember app integration testing using this api.