udemy-node-tests/spies/app.tests.js

26 lines
615 B
JavaScript
Raw Permalink Normal View History

2017-11-29 03:52:44 +00:00
const expect = require('expect');
2017-11-29 03:58:36 +00:00
const reqire = require('rewire');
2017-11-29 03:52:44 +00:00
2017-11-29 03:58:36 +00:00
var app = reqire('./app');
// app.__set__
// app.__get__
2017-11-29 03:52:44 +00:00
describe('App', () => {
2017-11-29 03:58:36 +00:00
var db = {
saveUser: expect.createSpy()
}
app.__set__('db', db);
it('should call the spy correctly', () => {
2017-11-29 03:52:44 +00:00
var spy = expect.createSpy();
spy('Andrew', 25);
2017-11-29 03:58:36 +00:00
expect(spy).toHaveBeenCalledWith('Andrew', 25);
});
it('should call saveUser with user object', () => {
var email = 'tits@tits.com'
var password = 'fakePass'
app.handleSignup(email, password);
expect(db.saveUser).toHaveBeenCalledWith({email, password})
2017-11-29 03:52:44 +00:00
})
})