Skip to content

Instantly share code, notes, and snippets.

@mwibutsa
Last active March 13, 2019 14:43
Show Gist options
  • Save mwibutsa/adb612ac4c18ea6ad60b7d50e95a0aa4 to your computer and use it in GitHub Desktop.
Save mwibutsa/adb612ac4c18ea6ad60b7d50e95a0aa4 to your computer and use it in GitHub Desktop.
Microsession TDD
import chai from 'chai';
import chaihttp from 'chai-http';
import app from '../app';
chai.should();
chai.use(chaihttp);
describe ('TEST GET ARTICLES', () => {
it ('should get Articles', (done) => {
chai.request(app).get('/api/v1/articles').then((res => {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('status').eql(200);
res.body.should.have.property('data');
res.body.data.should.be.a('array');
res.body.data.forEach((data) => {
data.should.be.a('object');
data.should.have.propery('title');
data.should.have.propery('content');
data.should.have.propery('id');
data.should.have.property('author');
});
}).catch(error => console.log(error))
});
});
@jnkindi
Copy link

jnkindi commented Mar 13, 2019

  • You didn't use eslint
  • in the Readme there is no v1 in the url description.
  • the test will fail because you did not follow this layout

`
{
"articles":[{
"slug": "how-to-train-your-dragon",
"title": "How to train your dragon",
"description": "Ever wonder how?",
"body": "It takes a Jacobian",
"tagList": ["dragons", "training"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favorited": false,
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}, {
"slug": "how-to-train-your-dragon-2",
"title": "How to train your dragon 2",
"description": "So toothless",
"body": "It a dragon",
"tagList": ["dragons", "training"],
"createdAt": "2016-02-18T03:22:56.637Z",
"updatedAt": "2016-02-18T03:48:35.824Z",
"favorited": false,
"favoritesCount": 0,
"author": {
"username": "jake",
"bio": "I work at statefarm",
"image": "https://i.stack.imgur.com/xHWG8.jpg",
"following": false
}
}],
"articlesCount": 2
}

`

@frankhn
Copy link

frankhn commented Mar 13, 2019

-Eslint

@Inclet
Copy link

Inclet commented Mar 13, 2019

Great Job!!
Here are few things to change:

  • You also need to test actual data it returned. For example, write res.body.data[0].should.have.property('title').eql('Something...') instead of res.body.data[0].should.have.property('title')

Meanwhile, You did a great job!!!

@mystere10
Copy link

Good job!

  1. Please eslint
  2. When writing describe u should use a meaningful phrase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment