Skip to content

Instantly share code, notes, and snippets.

@ndemengel
Last active November 13, 2016 19:14
Show Gist options
  • Save ndemengel/49ced6abf6b797b2b9e1de7a14d23196 to your computer and use it in GitHub Desktop.
Save ndemengel/49ced6abf6b797b2b9e1de7a14d23196 to your computer and use it in GitHub Desktop.
jsdom example
const tu = require('../tu'); // tu == test utils
const expect = tu.expect;
const withDocument = tu.withDocument;
const componentHtmlAndScript = {
html: `
<textarea id="editableArea"></textarea>
<div id="counter"></div>
`,
// load the JS module under test
hopModules: 'Hop/components/remaining-chars-counter'
};
describe('Remaining Chars Counter', () => {
it('should count down remaining chars', withDocument(componentHtmlAndScript, ($ /*, win, doc*/) => {
// given
// skipped: initialization of the JS module under test...
const $editableArea = $('#editableArea');
const $counter = $('#counter');
// when
$editableArea.val('123').trigger("input");
// then
expect($counter.text()).to.equal('remaining: 7 chars');
// when
$editableArea.val('123456789').trigger("input");
// then
expect($counter.text()).to.equal('remaining: 1 char');
// when
$editableArea.val('12345').trigger("input");
// then
expect($counter.text()).to.equal('remaining: 5 chars');
// etc.
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment