This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The exact same test using async/await | |
describe('#getUser() using async/await', () => { | |
it('should load user data', async () => { | |
const data = await github.getUser('vnglst') | |
expect(data).toBeDefined() | |
expect(data.entity.name).toEqual('Koen van Gilst') | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"login": "vnglst", | |
"id": 3457693, | |
"avatar_url": "https://avatars.githubusercontent.com/u/3457693?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/vnglst", | |
"html_url": "https://github.com/vnglst", | |
"followers_url": "https://api.github.com/users/vnglst/followers", | |
"following_url": "https://api.github.com/users/vnglst/following{/other_user}", | |
"gists_url": "https://api.github.com/users/vnglst/gists{/gist_id}", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const request = (url) => new Promise((resolve, reject) => { | |
// Get userID from supplied url string | |
const lastSlash = url.lastIndexOf('/') | |
const userID = url.substring(lastSlash + 1) | |
// Load user json data from a file in de subfolder for mock data | |
fs.readFile(`./src/api/__mockData__/${userID}.json`, 'utf8', (err, data) => { | |
if (err) reject(err) | |
// Parse the data as JSON and put in the key entity (just like the request library does) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env jest */ | |
const github = require('../github') | |
// A simple example test | |
describe('#getUser() using Promises', () => { | |
it('should load user data', () => { | |
return github.getUser('vnglst') | |
.then(data => { | |
expect(data).toBeDefined() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request from './request' | |
const getUser = user => request(`https://api.github.com/users/${user}`) | |
export { getUser } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rest = require('rest') | |
const mime = require('rest/interceptor/mime') | |
export default rest.wrap(mime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import './App.css' | |
import { getUser } from './api/github' | |
const renderLine = (user, key) => <li key={key}><b>{key}</b>: {user[key]}</li> | |
class App extends Component { | |
constructor (props) { | |
super(props) | |
this.state = { user: {} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .... | |
import LoaderHOC from './LoaderHOC' | |
// ... | |
class ContactsApp extends Component { | |
// ... | |
} | |
export default LoaderHOC(ContactsApp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
// Returns an empty "loader" div if empty, | |
// Return unchanged WrappedComponent if not empty | |
const LoaderHOC = (WrappedComponent) => { | |
return class LoaderOC extends Component { | |
render() { | |
return (!this.props.question) | |
? <div className='loading'></div> | |
: <WrappedComponent {...this.props} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
var index = require('./routes/index'); | |
var users = require('./routes/users'); | |
var pdf = require(‘./routes/pdf’); // <-- add this line | |
... | |
app.use('/', index); | |
app.use('/users', users); | |
app.use('/pdf', pdf); // <-- add this line | |
... |