This file contains hidden or 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 handler = { | |
| get: function(obj, prop) { | |
| console.log('A value has been accessed'); | |
| return obj[prop]; | |
| }, | |
| set: function(obj, prop, value) { | |
| console.log(`${prop} is being set to ${value}`); | |
| } | |
| } |
This file contains hidden or 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 handler = { | |
| get: function(obj, prop) { | |
| if (prop === 'id') { // Check if the id is being accessed | |
| throw new Error('Cannot access private properties!'); // Throw an error | |
| } else { | |
| return obj[prop]; // If it's not the id property, return it as usual | |
| } | |
| } | |
| } |
This file contains hidden or 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 handler = { | |
| set: function(obj, prop, value) { | |
| if (typeof value !== 'string') { | |
| throw new Error('Only string values can be stored in this object!'); | |
| } else { | |
| obj[prop] = value; | |
| } | |
| } | |
| } |
This file contains hidden or 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 express = require('express'); | |
| const app = express(); | |
| const port = 3000; | |
| app.get('/ping', (req, res) => { | |
| res.send('Pong!'); | |
| }); | |
| app.get('/status', (req, res) => { | |
| res.send('Ok'); |
This file contains hidden or 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 request = require('supertest'); | |
| const app = require('../server'); | |
| describe('Test /ping', () => { | |
| it ('should return Pong!', async () => { | |
| const response = await request(app).get('/ping'); | |
| expect(response.text).toBe('Pong!'); | |
| }); | |
| }); |
This file contains hidden or 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 request = require('supertest'); | |
| const app = require('../server/demo-server'); | |
| describe('Test /status', () => { | |
| it('should return Ok', async () => { | |
| const response = await request(app).get('/status'); | |
| expect(response.text).toBe('Ok'); | |
| }); | |
| }); |
This file contains hidden or 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 express = require('express'); | |
| const app = express(); | |
| const port = 3000; | |
| app.get('/ping', (req, res) => { | |
| res.send('Pong!'); | |
| }); | |
| app.get('/status', (req, res) => { | |
| res.send('Ok'); |
This file contains hidden or 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 from 'react'; | |
| import { render } from 'react-dom'; | |
| import { BrowserRouter } from 'react-router-dom'; | |
| import Routes from '../shared/routes'; | |
| const App = () => ( | |
| <BrowserRouter> | |
| <Routes /> | |
| </BrowserRouter> |
This file contains hidden or 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 from 'react'; | |
| import { Switch, Route } from 'react-router-dom'; | |
| import Feed from './containers/Feed'; | |
| import PostView from './containers/PostView'; | |
| const Routes = () => ( | |
| <Switch> | |
| <Route exact path="/" component={Feed} /> | |
| <Route path="/:slug" component={PostView} /> |
This file contains hidden or 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 from 'react'; | |
| import ReactDOMServer from 'react-dom/server'; | |
| import { StaticRouter } from 'react-router-dom'; | |
| import Routes from '../shared/routes'; | |