This commit is contained in:
Tyrel Souza 2017-11-28 22:14:07 -05:00
commit 264c681dc7
6 changed files with 1212 additions and 0 deletions

1084
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "node-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/server.js",
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"hbs": "^4.0.1"
},
"devDependencies": {
"atom-ui-reporter": "0.0.1",
"expect": "^1.20.2",
"mocha": "^3.0.0",
"supertest": "^2.0.0"
}
}

16
server/server.js Normal file
View File

@ -0,0 +1,16 @@
const express = require('express');
var app = express();
app.get('/', (req, res) => {
// res.send("it loaded");
res.status(404).send({
error: "Page not found",
name: "Todo App 1.0"
})
});
app.listen(3000);
module.exports.app = app;

16
server/server.test.js Normal file
View File

@ -0,0 +1,16 @@
const request = require('supertest')
const expect = require('expect')
var app = require('./server').app;
it('should return hello world response', (done) => {
request(app)
.get('/')
.expect(404)
.expect((res) => {
expect(res.body).toInclude({
error: 'Page not found'
})
})
.end(done);
});

20
utils/utils.js Normal file
View File

@ -0,0 +1,20 @@
module.exports.add = (a, b) => a + b;
module.exports.asyncAdd = (a, b, callback) => {
setTimeout(() => {
callback(a + b);
}, 50);
}
module.exports.square = (x) => x * x;
module.exports.asyncSquare = (a, callback) => {
setTimeout(() => {
callback(a * a);
}, 50);
}
module.exports.setName = (user, fullName) => {
var names = fullName.split(" ");
user.firstName = names[0];
user.lastName = names[1];
return user;
}

52
utils/utils.test.js Normal file
View File

@ -0,0 +1,52 @@
const expect = require('expect');
const utils = require("./utils");
it('should add two numbers', () => {
var res = utils.add(33, 11);
expect(res).toBe(44).toBeA('number');
});
it('should add two numbers async', (done) => {
utils.asyncAdd(33, 11, (sum) => {
expect(sum).toBe(44).toBeA('number');
done();
});
});
it('should add square a number', (done) => {
utils.asyncSquare(3, (total) => {
expect(total).toBe(9).toBeA('number');
done();
});
});
it('should square a number', () => {
var res = utils.square(13);
expect(res).toBe(169).toBeA('number');
});
it('should set the name', () => {
var user = { age: 29, location: "Boston" };
var res = utils.setName(user, "Tyrel Souza");
expect(res).toInclude({
age: user.age,
firstName: "Tyrel",
lastName: "Souza",
}).toBeA('object');
})
// it('shouled expect some values', () => {
// // expect(12).toNotBe(11)
// // expect({name: 'Tyrel'}).toEqual({name: 'Tyrel'});
// // expect([2, 3, 4]).toInclude(4)
// // expect({
// // name: 'Tyrel',
// // age: 29,
// // location: 'Boston'
// // }).toInclude({age: 29})
//
// })