Skip to content

Instantly share code, notes, and snippets.

@stacyp2006
Forked from khalidwilliams/10_19 testing review.md
Last active October 19, 2020 16:39
Show Gist options
  • Save stacyp2006/d1c651d973a8178b61af47fb53980de8 to your computer and use it in GitHub Desktop.
Save stacyp2006/d1c651d973a8178b61af47fb53980de8 to your computer and use it in GitHub Desktop.

Don't forget to call for help if you need it in your breakout rooms!

Warm Up

  • What does the async keyword do?

    • Used to make a fxn asynchronous. It goes before the word fxn in es5, in es6 before the parens.
    • Allows us to use the await keyword within the fxn.
    • Makes a fxn return a promise
  • What does the await keyword do?

    • Must be used in a fxn declared with the async keyword
    • Allows us to access a resolved value of a promise
    • It allows us to block the callstack of a fxn w/async code
    • Allows us to run async code as if it were synchronous
  • Convert this function to use async / await: ( https://repl.it/@khalidwilliams/2006M3-async-await-practice )

    // https://api.adviceslip.com/
    
    function getAdvice () {
    	fetch('https://api.adviceslip.com/advice')
    		.then(response  => response.json())
    		.then(adviceSlip => console.log(adviceSlip.advice))
    		.catch(error => console.error(error));
    }
    
    getAdvice();
  • Why would you mock a network request in a test?

    • Allows us to control what is returned
    • Prevents us from making actual network requests, potentially saving time and money
  • At a high level, what steps are necessary to mock out a network request?

  • Other questions? Put them here: https://docs.google.com/document/d/1td50LnCOA8VbAVA0KlOjm31Ach6F5NEQCy4QxgZhmOA/edit#

Hint: Don't be afraid to look at documentation for any of these questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment