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",
|
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
|
||||||
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
|
"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": {
|
"right-align": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"atom-ui-reporter": "0.0.1",
|
"atom-ui-reporter": "0.0.1",
|
||||||
"expect": "^1.20.2",
|
"expect": "^1.20.2",
|
||||||
"mocha": "^3.0.0",
|
"mocha": "^3.0.0",
|
||||||
|
"rewire": "^2.5.2",
|
||||||
"supertest": "^2.0.0"
|
"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);
|
app.listen(3000);
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
const request = require('supertest')
|
const request = require('supertest')
|
||||||
const expect = require('expect')
|
const expect = require('expect')
|
||||||
|
|
||||||
var app = require('./server').app;
|
var app = require('./server').app;
|
||||||
|
|
||||||
|
describe('Server', () => {
|
||||||
|
|
||||||
|
describe('/', () => {
|
||||||
it('should return hello world response', (done) => {
|
it('should return hello world response', (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
@ -10,7 +12,26 @@ it('should return hello world response', (done) => {
|
|||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
expect(res.body).toInclude({
|
expect(res.body).toInclude({
|
||||||
error: 'Page not found'
|
error: 'Page not found'
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.end(done);
|
.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
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,19 +1,23 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const utils = require("./utils");
|
const utils = require("./utils");
|
||||||
|
|
||||||
|
describe('Utils', () => {
|
||||||
|
|
||||||
|
describe("#add", () => {
|
||||||
it('should add two numbers', () => {
|
it('should add two numbers', () => {
|
||||||
var res = utils.add(33, 11);
|
var res = utils.add(33, 11);
|
||||||
expect(res).toBe(44).toBeA('number');
|
expect(res).toBe(44).toBeA('number');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add two numbers async', (done) => {
|
it('should add two numbers async', (done) => {
|
||||||
utils.asyncAdd(33, 11, (sum) => {
|
utils.asyncAdd(33, 11, (sum) => {
|
||||||
expect(sum).toBe(44).toBeA('number');
|
expect(sum).toBe(44).toBeA('number');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
|
||||||
it('should add square a number', (done) => {
|
describe("#square", () => {
|
||||||
|
it('should square a number', (done) => {
|
||||||
utils.asyncSquare(3, (total) => {
|
utils.asyncSquare(3, (total) => {
|
||||||
expect(total).toBe(9).toBeA('number');
|
expect(total).toBe(9).toBeA('number');
|
||||||
done();
|
done();
|
||||||
@ -25,6 +29,8 @@ it('should square a number', () => {
|
|||||||
expect(res).toBe(169).toBeA('number');
|
expect(res).toBe(169).toBeA('number');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
it('should set the name', () => {
|
it('should set the name', () => {
|
||||||
var user = { age: 29, location: "Boston" };
|
var user = { age: 29, location: "Boston" };
|
||||||
|
|
||||||
@ -37,6 +43,8 @@ it('should set the name', () => {
|
|||||||
}).toBeA('object');
|
}).toBeA('object');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it('shouled expect some values', () => {
|
// it('shouled expect some values', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user