testing
This commit is contained in:
parent
264c681dc7
commit
02cc9f37d3
6
package-lock.json
generated
6
package-lock.json
generated
@ -845,6 +845,12 @@
|
||||
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
|
||||
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
|
||||
},
|
||||
"rewire": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/rewire/-/rewire-2.5.2.tgz",
|
||||
"integrity": "sha1-ZCfee3/u+n02QBUH62SlOFvFjcc=",
|
||||
"dev": true
|
||||
},
|
||||
"right-align": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
|
||||
|
@ -19,6 +19,7 @@
|
||||
"atom-ui-reporter": "0.0.1",
|
||||
"expect": "^1.20.2",
|
||||
"mocha": "^3.0.0",
|
||||
"rewire": "^2.5.2",
|
||||
"supertest": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,16 @@ app.get('/', (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
app.get('/users', (req, res) => {
|
||||
res.send([
|
||||
{name: 'Tyrel', age: 29},
|
||||
{name: 'Lauren', age: 32},
|
||||
{name: 'Max', age: 33}
|
||||
])
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
app.listen(3000);
|
||||
|
||||
|
@ -1,16 +1,37 @@
|
||||
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'
|
||||
describe('Server', () => {
|
||||
|
||||
describe('/', () => {
|
||||
it('should return hello world response', (done) => {
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(404)
|
||||
.expect((res) => {
|
||||
expect(res.body).toInclude({
|
||||
error: 'Page not found'
|
||||
});
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('/users', () => {
|
||||
it('should return my user object', (done) => {
|
||||
request(app)
|
||||
.get('/users')
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.body).toInclude({
|
||||
name: "Tyrel",
|
||||
age:29
|
||||
});
|
||||
})
|
||||
})
|
||||
.end(done);
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
10
spies/app.js
Normal file
10
spies/app.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports.handleSignup = (email, password) => {
|
||||
|
||||
// Check if email already exists
|
||||
db.saveUser({
|
||||
email,
|
||||
pasword
|
||||
});
|
||||
// Send welcome email
|
||||
|
||||
}
|
9
spies/app.tests.js
Normal file
9
spies/app.tests.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
|
||||
describe('App', () => {
|
||||
it('should call the spy correctly',() => {
|
||||
var spy = expect.createSpy();
|
||||
spy('Andrew', 25);
|
||||
expect(spy).toHaveBeenCalled('Andrew', 25);
|
||||
})
|
||||
})
|
3
spies/db.js
Normal file
3
spies/db.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports.saveUser = (user) => {
|
||||
console.log("Saving user", user);
|
||||
}
|
@ -1,40 +1,48 @@
|
||||
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');
|
||||
});
|
||||
describe('Utils', () => {
|
||||
|
||||
describe("#add", () => {
|
||||
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();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe("#square", () => {
|
||||
it('should 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 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 set the name', () => {
|
||||
var user = { age: 29, location: "Boston" };
|
||||
|
||||
it('should square a number', () => {
|
||||
var res = utils.square(13);
|
||||
expect(res).toBe(169).toBeA('number');
|
||||
});
|
||||
var res = utils.setName(user, "Tyrel Souza");
|
||||
|
||||
it('should set the name', () => {
|
||||
var user = { age: 29, location: "Boston" };
|
||||
expect(res).toInclude({
|
||||
age: user.age,
|
||||
firstName: "Tyrel",
|
||||
lastName: "Souza",
|
||||
}).toBeA('object');
|
||||
})
|
||||
|
||||
var res = utils.setName(user, "Tyrel Souza");
|
||||
|
||||
expect(res).toInclude({
|
||||
age: user.age,
|
||||
firstName: "Tyrel",
|
||||
lastName: "Souza",
|
||||
}).toBeA('object');
|
||||
})
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user