unexpected
unexpected copied to clipboard
Handle throwing property getters
@Munter saw an error with unexpected-dom that seems to be caused by an HTMLInputElement throwing when the selectionDirection property is accessed under some circumstances.
it('should not check any radio buttons when there is no value', function () {
var instance = ReactTestUtils.renderIntoDocument(
<RadioGroup>
<input type="radio" value="one" />
<input type="radio" value="two" />
</RadioGroup>);
var inputs = Array.prototype.slice.call(instance.getDOMNode().querySelectorAll('input[type="radio"]'));
expect(inputs, 'to have length', 2);
expect(inputs, 'to be an array whose items satisfy', function (input) {
expect(input.getAttribute('checked'), 'to be', null);
expect(input.checked, 'to be', null);
});
});
Chrome 41.0.2272 (Mac OS X 10.9.5) RadioGroupComponent value should not check any radio buttons when there is no value FAILED
Error: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('radio') does not support selection.
at Error (native)
at /Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:2058:72
at Array.map (native)
at Object.expect.addType.inspect (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:2045:39)
at Object.extendedType.inspect (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:454:28)
at printOutput (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:284:24)
at /Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:290:20
at Object.expect.addType.inspect (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:2279:41)
at Object.extendedType.inspect (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:454:28)
at Object.extendedType.inspect (/Users/munter/src/frontend-rails/app/assets/javascripts/bower_components/unexpected/unexpected.js:454:28)
Here's a smaller test case where it would make sense to get a diff-like output with the error instance inspected. Maybe it should even be possible to assert that a getter throws?
> require('unexpected')({get foo() {throw new Error();}}, 'to satisfy', {foo: 123})
Error
at Object.foo (repl:1:42)
at /home/andreas/work/node_modules/unexpected/lib/assertions.js:586:39
at Array.forEach (native)
at Assertion.<anonymous> (/home/andreas/work/node_modules/unexpected/lib/assertions.js:585:26)
at Unexpected.expect (/home/andreas/work/node_modules/unexpected/lib/Unexpected.js:629:21)
at repl:1:23
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)