Set up / teardown container div in before/afterEach

This commit is contained in:
David Baker 2016-06-17 15:50:13 +01:00
parent b2f0ed09ab
commit 53d92df6f8

View file

@ -15,9 +15,11 @@ var stubComponent = require('../../components/stub-component.js');
describe('RoomView', function () { describe('RoomView', function () {
var sandbox; var sandbox;
var parentDiv;
beforeEach(function() { beforeEach(function() {
sandbox = test_utils.stubClient(); sandbox = test_utils.stubClient();
parentDiv = document.createElement('div');
this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel'); this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel');
this.oldRoomHeader = Skinner.getComponent('views.rooms.RoomHeader'); this.oldRoomHeader = Skinner.getComponent('views.rooms.RoomHeader');
@ -29,6 +31,9 @@ describe('RoomView', function () {
afterEach(function() { afterEach(function() {
sandbox.restore(); sandbox.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel); Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel);
Skinner.addComponent('views.rooms.RoomHeader', this.oldRoomHeader); Skinner.addComponent('views.rooms.RoomHeader', this.oldRoomHeader);
}); });
@ -38,7 +43,6 @@ describe('RoomView', function () {
var onRoomIdResolved = sinon.spy(); var onRoomIdResolved = sinon.spy();
var parentDiv = document.createElement('div');
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv); ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
process.nextTick(function() { process.nextTick(function() {
@ -46,7 +50,6 @@ describe('RoomView', function () {
// messages, but expect's toHaveBeenCalled only takes an expect spy object, // messages, but expect's toHaveBeenCalled only takes an expect spy object,
// not a sinon spy object. // not a sinon spy object.
expect(onRoomIdResolved.called).toExist(); expect(onRoomIdResolved.called).toExist();
ReactDOM.unmountComponentAtNode(parentDiv);
done(); done();
}); });
}); });
@ -63,7 +66,6 @@ describe('RoomView', function () {
roomView.onJoinButtonClicked(); roomView.onJoinButtonClicked();
process.nextTick(function() { process.nextTick(function() {
expect(peg.get().joinRoom.calledWith('#alias:ser.ver')).toExist(); expect(peg.get().joinRoom.calledWith('#alias:ser.ver')).toExist();
ReactDOM.unmountComponentAtNode(parentDiv);
done(); done();
}); });
}); });