Skip to content

Commit

Permalink
adds test for instanceOf, #115
Browse files Browse the repository at this point in the history
  • Loading branch information
brigand committed Jul 10, 2017
1 parent 905320e commit 0223423
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/__tests__/__snapshots__/browser-global-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`global element 1`] = `
"\\"use strict\\";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\\"value\\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\\"Cannot call a class as a function\\"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\\"this hasn't been initialised - super() hasn't been called\\"); } return call && (typeof call === \\"object\\" || typeof call === \\"function\\") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== \\"function\\" && superClass !== null) { throw new TypeError(\\"Super expression must either be null or a function, not \\" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Element = window.Element;
var Foo = function (_React$Component) {
_inherits(Foo, _React$Component);
function Foo() {
_classCallCheck(this, Foo);
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
}
_createClass(Foo, [{
key: \\"render\\",
value: function render() {
return null;
}
}]);
return Foo;
}(React.Component);
Foo.propTypes = {
element: typeof Element === \\"function\\" ? require(\\"prop-types\\").instanceOf(Element).isRequired : require(\\"prop-types\\").any.isRequired
};"
`;
24 changes: 24 additions & 0 deletions src/__tests__/browser-global-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const babel = require('babel-core');
const content = `
const Element = window.Element;
type FooProps = {
element: Element,
}
class Foo extends React.Component {
props: FooProps;
render() { return null; }
}
`;

it('global element', () => {
const res = babel.transform(content, {
babelrc: false,
presets: ['es2015', 'stage-1', 'react'],
plugins: ['syntax-flow', require('../')],
}).code;
expect(res).toMatchSnapshot();
});

0 comments on commit 0223423

Please sign in to comment.