-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stephen's frontend-api-challenge #125
base: master
Are you sure you want to change the base?
Conversation
class ChitterApi { | ||
|
||
loadPeeps(callback) { | ||
const callbackFn = callback || (() => { }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You reference this a lot - not sure why you have it but you could make it a line in the constructor eg. this.callbackFn()
instead of writing it every time
// const divEl = this.makeElement('#main-container', 'div', 'post-peep'); | ||
const divEl = document.querySelector('#post-peep') | ||
|
||
const peepEl = this.makeElement('#post-peep', 'input', 'post-content'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really like this quick way of making an element!
}) | ||
|
||
it('displays peeps', () => { | ||
const peepsView = new PeepsView(model); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be in beforeEach
model = new PeepsModel; | ||
}) | ||
|
||
it('displays peeps', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this only tests that you display a single peep, would it not be worth testing for multiple peeps?
} | ||
] | ||
|
||
const api = { loadPeeps: (callback) => callback(peep) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is a mocked function you could test that this is being called at all
}) | ||
|
||
it('posts a peep', () => { | ||
const peeps = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be saved as a variable accessible by multiple tests instead of repeating the same code
@@ -0,0 +1,143 @@ | |||
class PeepsView { | |||
constructor(model, api) { | |||
this.user_id = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saved this data to model rather than view as model is for saving data and view is for displaying it, not sure if that's correct though
} | ||
|
||
makeElement(parent, type, id) { | ||
const El = document.createElement(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variables need to be lower case first letter
My effort at test driving a JavaScript single page frontend app interfacing with the makers API to:
It's rough around the edges but all code is test driven.