Skip to content

Instantly share code, notes, and snippets.

@feynon
Forked from mpj/episode.js
Created August 29, 2019 13:30
Show Gist options
  • Select an option

  • Save feynon/0339b0d35dd17ddfc84c1316ad112603 to your computer and use it in GitHub Desktop.

Select an option

Save feynon/0339b0d35dd17ddfc84c1316ad112603 to your computer and use it in GitHub Desktop.

Revisions

  1. @mpj mpj created this gist Jan 15, 2017.
    39 changes: 39 additions & 0 deletions episode.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    const assert = require('assert')

    function getAnimals(fetch, id) {
    return fetch('http://api.animalfarmgame.com/animals/' + id)
    .then(response => response.json())
    .then(data => data.results[0])
    }

    describe('getAnimals', () => {
    it('calls fetch with the correct url', () => {
    const fakeFetch = url => {
    assert(
    url ===
    'http://api.animalfarmgame.com/animals/123'
    )
    return new Promise(function(resolve) {

    })
    }
    getAnimals(fakeFetch, 123)
    })

    it('parses the response of fetch correctly', (done) => {
    const fakeFetch = () => {
    return Promise.resolve({
    json: () => Promise.resolve({
    results: [
    { name: 'fluffykins' }
    ]
    })
    })
    }
    getAnimals(fakeFetch, 12345)
    .then(result => {
    assert(result.name === 'fluffykins')
    done()
    })
    })
    })