From ec8754f22eef4a0c81c80afe34924a0c11d08493 Mon Sep 17 00:00:00 2001 From: Kai Schaper <303@posteo.de> Date: Wed, 12 Oct 2016 18:06:18 +0200 Subject: [PATCH 1/2] add chai-enzyme; add/improve Avatar component specs --- package.json | 1 + spec/javascript/components/avatar.test.jsx | 22 ++++++++++++++++++---- spec/javascript/setup.js | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 133244650f..3d1878e15a 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "browserify": "^13.1.0", "browserify-incremental": "^3.1.1", "chai": "^3.5.0", + "chai-enzyme": "^0.5.2", "enzyme": "^2.4.1", "es6-promise": "^3.2.1", "immutable": "^3.8.1", diff --git a/spec/javascript/components/avatar.test.jsx b/spec/javascript/components/avatar.test.jsx index 79b7d02f46..a0f67e700b 100644 --- a/spec/javascript/components/avatar.test.jsx +++ b/spec/javascript/components/avatar.test.jsx @@ -4,9 +4,23 @@ import { render } from 'enzyme'; import Avatar from '../../../app/assets/javascripts/components/components/avatar' describe('', () => { - it('renders an img with the given src', () => { - const src = '/path/to/image.jpg'; - const wrapper = render(); - expect(wrapper.find(`img[src="${src}"]`)).to.have.length(1); + const src = '/path/to/image.jpg'; + const size = 100; + const wrapper = render(); + + it('renders an img element with the given src', () => { + expect(wrapper.find('img')).to.have.attr('src', `${src}`); + }); + + it('renders an img element of the given size', () => { + ['width', 'height'].map((attr) => { + expect(wrapper.find('img')).to.have.attr(attr, `${size}`); + }); + }); + + it('renders a div element of the given size', () => { + ['width', 'height'].map((attr) => { + expect(wrapper.find('div')).to.have.style(attr, `${size}px`); + }); }); }); diff --git a/spec/javascript/setup.js b/spec/javascript/setup.js index 636cdcc7e3..0d07f74d88 100644 --- a/spec/javascript/setup.js +++ b/spec/javascript/setup.js @@ -1,3 +1,7 @@ +import chai from 'chai'; +import chaiEnzyme from 'chai-enzyme'; +chai.use(chaiEnzyme()); + /** * http://airbnb.io/enzyme/docs/guides/jsdom.html */ From 89ccac45220da8bff52b4718952b0e1064a305da Mon Sep 17 00:00:00 2001 From: Kai Schaper <303@posteo.de> Date: Wed, 12 Oct 2016 18:18:55 +0200 Subject: [PATCH 2/2] actually use const --- spec/javascript/components/avatar.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/javascript/components/avatar.test.jsx b/spec/javascript/components/avatar.test.jsx index a0f67e700b..852e13a89c 100644 --- a/spec/javascript/components/avatar.test.jsx +++ b/spec/javascript/components/avatar.test.jsx @@ -6,7 +6,7 @@ import Avatar from '../../../app/assets/javascripts/components/components/avatar describe('', () => { const src = '/path/to/image.jpg'; const size = 100; - const wrapper = render(); + const wrapper = render(); it('renders an img element with the given src', () => { expect(wrapper.find('img')).to.have.attr('src', `${src}`);