Created
February 21, 2016 10:21
-
-
Save wolframkriesing/2471b3a46767998bdb75 to your computer and use it in GitHub Desktop.
workshop part #1
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
var assert = require('assert'); | |
var hamjest = require('hamjest'); | |
var promiseThat = hamjest.promiseThat; | |
var isRejectedWith = hamjest.isRejectedWith; | |
var KATAS_URL = 'http://katas.tddbin.com/katas/es6/language/__grouped__.json'; | |
var INVALID_URL = 'http://katas.tddbin.com/katas/es6/language/__all__.json'; | |
var fetch = require('node-fetch'); | |
function loadKatasJsonFrom(url) { | |
return fetch(url) | |
.then(function(res) { | |
return res.json(); | |
}) | |
.catch(function() { | |
throw 'Error loading katas.' | |
}) | |
.then(function(katasJson) { | |
if ('groups' in katasJson) { | |
return katasJson; | |
} | |
throw 'Invalid JSON format.' | |
}) | |
; | |
} | |
describe('loading the katas JSON', () => { | |
it('works', () => { | |
return loadKatasJsonFrom(KATAS_URL); | |
}); | |
it('bails for non-JSON data', () => { | |
return promiseThat(loadKatasJsonFrom('http://es6katas.org'), | |
isRejectedWith('Error loading katas.') | |
); | |
}); | |
it('bails for invalid JSON data', () => { | |
return promiseThat(loadKatasJsonFrom(INVALID_URL), | |
isRejectedWith('Invalid JSON format.') | |
); | |
}); | |
}); |
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
{ | |
"name": "es6-workshop-2016", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "mocha src", | |
"watch:test": "npm test -- --watch" | |
}, | |
"author": "", | |
"license": "MIT", | |
"devDependencies": { | |
"hamjest": "^2.13.0", | |
"mocha": "^2.4.5", | |
"node-fetch": "^1.3.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment