Replace chai with unexpected.js

This commit is contained in:
SleepWalker
2016-07-30 13:44:43 +03:00
parent ae11dbdc97
commit 9abbe2ebab
12 changed files with 221 additions and 144 deletions

View File

@@ -1,3 +1,5 @@
import expect from 'unexpected';
import React from 'react';
import { shallow, mount } from 'enzyme';
@@ -22,7 +24,7 @@ describe('<PopupStack />', () => {
};
const component = shallow(<PopupStack {...props} />);
expect(component.find(DummyPopup)).to.have.length(2);
expect(component.find(DummyPopup), 'to satisfy', {length: 2});
});
it('should pass onClose as props', () => {
@@ -35,7 +37,7 @@ describe('<PopupStack />', () => {
popups: [
{
Popup: (props = {}) => {
expect(props.onClose).to.be.a('function');
expect(props.onClose, 'to be a', 'function');
return <DummyPopup {...expectedProps} />;
}
@@ -45,8 +47,8 @@ describe('<PopupStack />', () => {
const component = mount(<PopupStack {...props} />);
const popup = component.find(DummyPopup);
expect(popup).to.have.length(1);
expect(popup.props()).to.deep.equal(expectedProps);
expect(popup, 'to satisfy', {length: 1});
expect(popup.props(), 'to equal', expectedProps);
});
it('should hide popup, when onClose called', () => {
@@ -59,20 +61,22 @@ describe('<PopupStack />', () => {
Popup: DummyPopup
}
],
destroy: sinon.stub()
destroy: sinon.stub().named('props.destroy')
};
const component = shallow(<PopupStack {...props} />);
component.find(DummyPopup).last().prop('onClose')();
sinon.assert.calledOnce(props.destroy);
sinon.assert.calledWith(props.destroy, sinon.match.same(props.popups[1]));
expect(props.destroy, 'was called once');
expect(props.destroy, 'to have a call satisfying', [
expect.it('to be', props.popups[1])
]);
});
it('should hide popup, when overlay clicked', () => {
const preventDefault = sinon.stub();
const preventDefault = sinon.stub().named('event.preventDefault');
const props = {
destroy: sinon.stub(),
destroy: sinon.stub().named('props.destroy'),
popups: [
{
Popup: DummyPopup
@@ -84,13 +88,13 @@ describe('<PopupStack />', () => {
const overlay = component.find(`.${styles.overlay}`);
overlay.simulate('click', {target: 1, currentTarget: 1, preventDefault});
sinon.assert.calledOnce(props.destroy);
sinon.assert.calledOnce(preventDefault);
expect(props.destroy, 'was called once');
expect(preventDefault, 'was called once');
});
it('should hide popup on overlay click if disableOverlayClose', () => {
const props = {
destroy: sinon.stub(),
destroy: sinon.stub().named('props.destroy'),
popups: [
{
Popup: DummyPopup,
@@ -103,12 +107,12 @@ describe('<PopupStack />', () => {
const overlay = component.find(`.${styles.overlay}`);
overlay.simulate('click', {target: 1, currentTarget: 1, preventDefault() {}});
sinon.assert.notCalled(props.destroy);
expect(props.destroy, 'was not called');
});
it('should hide popup, when esc pressed', () => {
const props = {
destroy: sinon.stub(),
destroy: sinon.stub().named('props.destroy'),
popups: [
{
Popup: DummyPopup
@@ -121,12 +125,12 @@ describe('<PopupStack />', () => {
event.which = 27;
document.dispatchEvent(event);
sinon.assert.calledOnce(props.destroy);
expect(props.destroy, 'was called once');
});
it('should hide first popup in stack if esc pressed', () => {
const props = {
destroy: sinon.stub(),
destroy: sinon.stub().named('props.destroy'),
popups: [
{
Popup() {return null;}
@@ -142,13 +146,15 @@ describe('<PopupStack />', () => {
event.which = 27;
document.dispatchEvent(event);
sinon.assert.calledOnce(props.destroy);
sinon.assert.calledWithExactly(props.destroy, props.popups[1]);
expect(props.destroy, 'was called once');
expect(props.destroy, 'to have a call satisfying', [
expect.it('to be', props.popups[1])
]);
});
it('should NOT hide popup on esc pressed if disableOverlayClose', () => {
const props = {
destroy: sinon.stub(),
destroy: sinon.stub().named('props.destroy'),
popups: [
{
Popup: DummyPopup,
@@ -162,6 +168,6 @@ describe('<PopupStack />', () => {
event.which = 27;
document.dispatchEvent(event);
sinon.assert.notCalled(props.destroy);
expect(props.destroy, 'was not called');
});
});

View File

@@ -1,3 +1,5 @@
import expect from 'unexpected';
import reducer from 'components/ui/popup/reducer';
import {create, destroy} from 'components/ui/popup/actions';
@@ -5,8 +7,8 @@ describe('popup/reducer', () => {
it('should have no popups by default', () => {
const actual = reducer(undefined, {});
expect(actual.popups).to.be.an('array');
expect(actual.popups).to.be.empty;
expect(actual.popups, 'to be an', 'array');
expect(actual.popups, 'to be empty');
});
describe('#create', () => {
@@ -15,7 +17,7 @@ describe('popup/reducer', () => {
Popup: FakeComponent
}));
expect(actual.popups[0]).to.be.deep.equal({
expect(actual.popups[0], 'to equal', {
Popup: FakeComponent
});
});
@@ -23,7 +25,7 @@ describe('popup/reducer', () => {
it('should support shortcut popup creation', () => {
const actual = reducer(undefined, create(FakeComponent));
expect(actual.popups[0]).to.be.deep.equal({
expect(actual.popups[0], 'to equal', {
Popup: FakeComponent
});
});
@@ -36,13 +38,13 @@ describe('popup/reducer', () => {
Popup: FakeComponent
}));
expect(actual.popups[1]).to.be.deep.equal({
expect(actual.popups[1], 'to equal', {
Popup: FakeComponent
});
});
it('throws when no type provided', () => {
expect(() => reducer(undefined, create())).to.throw('Popup is required');
expect(() => reducer(undefined, create()), 'to throw', 'Popup is required');
});
});
@@ -56,11 +58,11 @@ describe('popup/reducer', () => {
});
it('should remove popup', () => {
expect(state.popups).to.have.length(1);
expect(state.popups, 'to have length', 1);
state = reducer(state, destroy(popup));
expect(state.popups).to.have.length(0);
expect(state.popups, 'to have length', 0);
});
it('should not remove something, that it should not', () => {
@@ -70,8 +72,8 @@ describe('popup/reducer', () => {
state = reducer(state, destroy(popup));
expect(state.popups).to.have.length(1);
expect(state.popups[0]).to.not.equal(popup);
expect(state.popups, 'to have length', 1);
expect(state.popups[0], 'not to be', popup);
});
});
});