1 |
|
2 |
|
3 | 'use strict';
|
4 | var expect = require('expect.js'),
|
5 | React = require('react'),
|
6 | DocumentTitle = require('../');
|
7 |
|
8 | describe('DocumentTitle (in a browser)', function () {
|
9 | afterEach(function () {
|
10 | React.unmountComponentAtNode(global.document.body);
|
11 | delete global.document.title;
|
12 | });
|
13 | before(function () {
|
14 |
|
15 | global.window = require('global/window');
|
16 | global.document = require('global/document');
|
17 | global.window.document = document;
|
18 | global.window.location = {};
|
19 | global.window.navigator = {userAgent: 'Chrome'};
|
20 | console.debug = console.log;
|
21 | });
|
22 | after(function () {
|
23 | delete global.window;
|
24 | delete global.document;
|
25 | delete console.debug;
|
26 | });
|
27 | it('changes the document title on mount', function (done) {
|
28 | var title = 'hello world';
|
29 | var Component = React.createClass({
|
30 | componentDidMount: function () {
|
31 | expect(global.document.title).to.equal(title);
|
32 | done();
|
33 | },
|
34 | render: function () {
|
35 | return React.createElement(DocumentTitle, {title: title});
|
36 | }
|
37 | });
|
38 | React.render(React.createElement(Component), global.document.body);
|
39 | });
|
40 | it('supports nesting', function (done) {
|
41 | var called = false;
|
42 | var title = 'hello world';
|
43 | var Component1 = React.createClass({
|
44 | componentDidMount: function () {
|
45 | setTimeout(function () {
|
46 | expect(called).to.be(true);
|
47 | expect(global.document.title).to.equal(title);
|
48 | done();
|
49 | });
|
50 | },
|
51 | render: function () {
|
52 | return React.createElement(DocumentTitle, {title: title});
|
53 | }
|
54 | });
|
55 | var Component2 = React.createClass({
|
56 | componentDidMount: function () {
|
57 | called = true;
|
58 | },
|
59 | render: function () {
|
60 | return React.createElement(DocumentTitle, {title: 'nope'},
|
61 | React.DOM.div(null, React.createElement(Component1))
|
62 | );
|
63 | }
|
64 | });
|
65 | React.render(React.createElement(Component2), global.document.body);
|
66 | });
|
67 | });
|