From 998f161e1d73ee699a99a65fa5e7701ea6602567 Mon Sep 17 00:00:00 2001 From: Kai Schaper <303@posteo.de> Date: Mon, 10 Oct 2016 22:32:03 +0200 Subject: add jsdom; add basic Avatar component test --- spec/javascript/components/avatar.test.jsx | 12 ++++++++++++ .../components/loading_indicator.test.jsx | 2 -- spec/javascript/setup.js | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 spec/javascript/components/avatar.test.jsx create mode 100644 spec/javascript/setup.js (limited to 'spec') diff --git a/spec/javascript/components/avatar.test.jsx b/spec/javascript/components/avatar.test.jsx new file mode 100644 index 000000000..f69b538a2 --- /dev/null +++ b/spec/javascript/components/avatar.test.jsx @@ -0,0 +1,12 @@ +import { expect } from 'chai'; +import { render } from 'enzyme'; + +import Avatar from '../../../app/assets/javascripts/components/components/avatar' + +describe('', function() { + it('renders an img with the given src', function() { + const src = '/path/to/image.jpg'; + const wrapper = render(); + expect(wrapper.find(`img[src="${src}"]`)).to.have.length(1); + }); +}); diff --git a/spec/javascript/components/loading_indicator.test.jsx b/spec/javascript/components/loading_indicator.test.jsx index b2f9c919e..e62288405 100644 --- a/spec/javascript/components/loading_indicator.test.jsx +++ b/spec/javascript/components/loading_indicator.test.jsx @@ -1,7 +1,5 @@ import { expect } from 'chai'; import { shallow } from 'enzyme'; -import React from 'react'; -global.React = React; import LoadingIndicator from '../../../app/assets/javascripts/components/components/loading_indicator' diff --git a/spec/javascript/setup.js b/spec/javascript/setup.js new file mode 100644 index 000000000..636cdcc7e --- /dev/null +++ b/spec/javascript/setup.js @@ -0,0 +1,22 @@ +/** + * http://airbnb.io/enzyme/docs/guides/jsdom.html + */ +var jsdom = require('jsdom').jsdom; + +var exposedProperties = ['window', 'navigator', 'document']; + +global.document = jsdom(''); +global.window = document.defaultView; +Object.keys(document.defaultView).forEach((property) => { + if (typeof global[property] === 'undefined') { + exposedProperties.push(property); + global[property] = document.defaultView[property]; + } +}); + +global.navigator = { + userAgent: 'node.js' +}; + +var React = window.React = global.React = require('react'); +var ReactDOM = window.ReactDOM = global.ReactDOM = require('react-dom'); -- cgit