Skip to content

Instantly share code, notes, and snippets.

@nackjicholson
Created January 14, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nackjicholson/dc6d67929a7c7130423a to your computer and use it in GitHub Desktop.
Save nackjicholson/dc6d67929a7c7130423a to your computer and use it in GitHub Desktop.
it('should check a default input by using the defaultValue prop', () => {
const props = {
defaultValue: 'bravo.value',
inputs: [
{ value: 'alpha.value', label: 'alpha.label' },
{ value: 'bravo.value', label: 'bravo.label' },
{ value: 'charlie.value', label: 'charlie.label' }
]
};
const component = createComponent(props);
const $component = $(component).render();
const $inputs = $component.find('input');
// Turning $inputs into an array of elements and then using `Array.prototype.filter`
// and `Array.prototype.map` to figure out which one on the DOM is "checked".
const actual = $inputs
.get()
.filter(inputNode => inputNode.checked)
.map(inputNode => inputNode.value);
const expected = ['bravo.value'];
// Then we assert that the "checked" input, is the bravo input, which is the
// the one indicated by the defaultValue prop.
assert.deepEqual(
actual,
expected,
'checked the input with the value equal to defaultValue prop'
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment