Skip to content

Commit

Permalink
end of lesson 7
Browse files Browse the repository at this point in the history
  • Loading branch information
twclark0 committed Jan 27, 2018
1 parent 4b9317b commit b2a515e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ class App extends Component {

state = {
complete : false,
firstName : ''
firstName : '',
starWars: {}
}

async componentDidMount() {
const data = await fetch('https://swapi.co/api/people/1/').then(res => res.json())
this.setState({starWars: data})
}

handleSubmit = e => {
Expand All @@ -17,7 +23,6 @@ class App extends Component {
this.setState({ complete: true })
}
document.cookie = `firstName=${this.state.firstName}`
throw new Error('Whoops!')
}

handleInput = e => {
Expand All @@ -42,6 +47,7 @@ class App extends Component {
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<h3 data-testid="starWars">{this.state.starWars.url ? 'Received StarWars data!' : 'Something went wrong'}</h3>
{ this.state.complete ?
<SuccessMessage />
:
Expand Down
18 changes: 16 additions & 2 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ let errors = []
beforeAll(async () => {
browser = await puppeteer.launch(isDebugging())
page = await browser.newPage()
await page.setRequestInterception(true)
page.on('request', interceptedRequest => {
if (interceptedRequest.url.includes('swapi')) {
interceptedRequest.abort()
} else {
interceptedRequest.continue()
}
})
page.on('console', c => {
console.log(c.text)
logs.push(c.text)
Expand All @@ -48,6 +56,8 @@ describe('on page load ', () => {
const listItems = await page.$$('[data-testid="navBarLi"]')

expect(navbar).toBe(true)
if (listItems.length !== 4)
await page.pdf({path: 'screenshot.png'})
expect(listItems.length).toBe(4)
})
describe('login form', () => {
Expand Down Expand Up @@ -84,14 +94,18 @@ describe('on page load ', () => {
expect(firstNameCookie).not.toBeUndefined()
})
})
test('does not have console logs', () => {
test.skip('does not have console logs', () => {
const newLogs = logs.filter( s => s !== '%cDownload the React DevTools for a better development experience: https://fb.me/react-devtools font-weight:bold')

expect(newLogs.length).toBe(0)
})
test('does not have exceptions', () => {
test.skip('does not have exceptions', () => {
expect(errors.length).toBe(0)
})
test('fails to fetch starWars endpoint', async () => {
const h3 = await page.$eval('[data-testid="starWars"]', e => e.innerHTML)
expect(h3).toBe('Something went wrong')
})
})

afterAll(() => {
Expand Down

0 comments on commit b2a515e

Please sign in to comment.