Last active
September 1, 2017 13:29
-
-
Save carlosble/fe58a2652c5a297798a8b046250f01fc to your computer and use it in GitHub Desktop.
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
<div id="cards-gui-container"> | |
<label for="deck1">Deck1:</label> | |
<input id="deck1"/> | |
<br> | |
<label for="deck2">Deck2:</label> | |
<input id="deck2"/> | |
<input id="whoWinsButton" type="button" value="Who wins?"/> | |
<br> | |
<label id="result">The winner is...</label> | |
</div> |
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
/* | |
npm install --save-dev babel-core | |
npm install --save-dev mocha | |
npm install --save-dev chai | |
npm install --save-dev jsdom | |
RUN THE TESTS: | |
./node_modules/.bin/mocha --compilers js:babel-core cards_es6.js | |
*/ | |
const expect = require('chai').expect; | |
const jsdom = require('jsdom'); | |
const fs = require('fs'); | |
/* | |
To-do list: | |
INPUT -> Output | |
[1,2] vs [3,4] -> Player2 wins 2 to 0 | |
[1] vs [1] -> Tie | |
[1,2] vs [2,1] -> Tie | |
[2] vs [1] -> Player1 wins 1 to 0 | |
[2] vs [] -> Error | |
[] vs [] -> Tie | |
Ranking: [1,2,3,4,5,6,7,8,9,J,Q,K] | |
*/ | |
function whoWins(deck1, deck2){ | |
return "TIE"; | |
} | |
describe("the application", () => { | |
before(() => { | |
const dom = new jsdom.JSDOM('' + | |
` | |
<!DOCTYPE html><html><head></head> | |
<body> | |
<div id="cards-gui-container"> | |
<label for="deck1">Deck1:</label> | |
<input id="deck1"/> | |
<br> | |
<label for="deck2">Deck2:</label> | |
<input id="deck2"/> | |
<input id="whoWinsButton" type="button" value="Who wins?"/> | |
<br> | |
<label id="result">The winner is...</label> | |
</div> | |
</body></html> | |
`); | |
global.window = dom.window; | |
global.document = dom.window.document; | |
}); | |
it('works', () => { | |
const deck1 = document.getElementById("deck1"); | |
deck1.value = "1,2"; | |
const deck2 = document.getElementById("deck2"); | |
deck2.value = "1,1"; | |
const button = document.getElementById("whoWinsButton"); | |
button.click(); | |
const result = document.getElementById("result"); | |
expect("Player1 wins 1 to 0").to.eql(result.innerHTML); | |
}); | |
}); | |
describe("the cards game", () => { | |
it("considers tie when there are no cards", () => { | |
expect("TIE").to.eql(whoWins([], [])); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment