Skip to content

Commit

Permalink
[#41] Тесты на componentDidMount вложенных компонент
Browse files Browse the repository at this point in the history
  • Loading branch information
vitkarpov committed Aug 15, 2016
1 parent df2a31b commit 49e71ce
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"license": "MIT",
"dependencies": {
"jquery": "^2.1.4",
"noscript": "^0.8.4",
"noscript": "^0.8.6",
"noscript-bosphorus": "0.0.5",
"react": "^0.14.1",
"react-dom": "^0.14.1",
Expand Down
80 changes: 80 additions & 0 deletions test/integration/ns.viewReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,84 @@ describe('ns.ViewReact интеграционные тесты ->', function() {
});
});
});

describe('[#41] componentDidMount вложенных реактовых компонент', function() {
beforeEach(function() {
ns.layout.define('app', {
app: 'v-1'
});
ns.layout.define('app2', {
app: {
'v-2': 'v-1'
}
});
ns.layout.define('app3', {
app: {
'boxYate@': 'v-1'
}
});
ns.layout.define('app4', {
app: {
'v-2': {
'boxReact@': 'v-1'
}
}
});
var _this = this;

ns.View.define('app');
ns.ViewReact.define('v-1', {
component: {
render: function() {
return React.createElement(React.createClass({
componentDidMount: function() {
_this.nodeV1 = ReactDOM.findDOMNode(this);
},
render: function() {
return React.createElement('div', {}, 'Hello, world!');
}
}));
}
}
});
ns.ViewReact.define('v-2');

this.appendAppNode();
ns.initMainView();
});
afterEach(function() {
ns.MAIN_VIEW.destroy();
});

describe('должен вызываться когда нода находится в DOM', function() {
it('для обычной вьюшки', function() {
return new ns.Update(ns.MAIN_VIEW, ns.layout.page('app', {}), {})
.render()
.then(function() {
expect($('body').find(this.nodeV1)).to.have.length.above(0);
}, this);
});
it('для вложенной вьюшки', function() {
return new ns.Update(ns.MAIN_VIEW, ns.layout.page('app2', {}), {})
.render()
.then(function() {
expect($('body').find(this.nodeV1)).to.have.length.above(0);
}, this);
});
it('для вьюшки в ns-боксе', function() {
return new ns.Update(ns.MAIN_VIEW, ns.layout.page('app3', {}), {})
.render()
.then(function() {
expect($('body').find(this.nodeV1)).to.have.length.above(0);
}, this);
});
it('для вьюшки в реакт-боксе', function() {
return new ns.Update(ns.MAIN_VIEW, ns.layout.page('app4', {}), {})
.render()
.then(function() {
expect($('body').find(this.nodeV1)).to.have.length.above(0);
}, this);
});
});
});
});
6 changes: 6 additions & 0 deletions test/stub/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ beforeEach(function() {
'data-key': this.key
}, props));
};

this.appendAppNode = function() {
var appNode = document.createElement('div');
appNode.setAttribute('id', 'app');
document.body.appendChild(appNode);
};
});

afterEach(function() {
Expand Down

0 comments on commit 49e71ce

Please sign in to comment.