{"size": 1230, "ext": "js", "max_stars_repo_path": "src/day_09/asyncAwait.test.js", "max_stars_repo_name": "kuga-uy/a-walk-in-javascript", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/day_09/asyncAwait.test.js", "max_issues_repo_name": "kuga-uy/a-walk-in-javascript", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/day_09/asyncAwait.test.js", "max_forks_repo_name": "kuga-uy/a-walk-in-javascript", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.625, "max_line_length": 80, "alphanum_fraction": 0.4528455285}
describe('DAY 9: Async/await', () => {
    /**
     * @param {string} outcome resolve|reject
     * @returns {Promise}
     */
    function fetchData (outcome) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                switch (outcome) {
                    case 'resolve':
                        resolve('data retrieved');
                        break;
                    default:
                        reject('no data');
                        break;
                }
            }, 50);
        });
    }

    // @see https://jestjs.io/docs/en/asynchronous for a hint
    it(`make an async test for fetchData to verify resolution`, async () => { 

        try {
            const url = 'https://api.weather.gov/gridpoints/TOP/31,80/forecast';
            await fetchData(url);
            expect(fetchData()).toMatch('data retrived');
          } catch (e) {
            console.log(e);
          }
    });

    // @see https://jestjs.io/docs/en/asynchronous for a hint
    it(`make an async test for fetchData to verify rejection`, async () => {
        try {
          await fetchData();
        } catch (e) {
          expect(e).toMatch('no data');
        }
    });
});






