UNPKG

1.62 kBJavaScriptView Raw
1import chai from 'chai';
2import sinon from 'sinon';
3import sinonChai from 'sinon-chai';
4
5var expect = chai.expect;
6
7chai.use(sinonChai)
8
9import {ClientApp} from '../index';
10var render;
11
12function buildCtx (path, data) {
13 var request = {
14 path: path,
15 method: 'GET',
16 };
17
18 return {
19 request,
20 path: request.path,
21 method: request.method,
22 redirect: sinon.spy(),
23 };
24}
25
26describe('ClientApp', function() {
27 beforeEach(function() {
28 render = sinon.spy();
29 });
30
31 it('is a thing', function() {
32 expect(ClientApp).to.not.be.null;
33 });
34
35 describe('state', function() {
36 it('can set default state', function() {
37 var state = {
38 data: 1,
39 };
40
41 var client = new ClientApp({
42 state: state,
43 });
44
45 expect(client.state).to.equal(state);
46 });
47
48 it('can set new state', function() {
49 var client = new ClientApp({
50 });
51
52 client.setState('a', 'b');
53 expect(client.state['a']).to.equal('b');
54 });
55
56 it('gets state by string', function() {
57 var state = { a: 'b' };
58
59 var client = new ClientApp({
60 });
61
62 client.state = state;
63
64 expect(client.getState('a')).to.equal('b');
65 });
66
67 it('can return entire state', function() {
68 var state = { a: 'b' };
69
70 var client = new ClientApp({
71 });
72
73 client.state = state;
74
75 expect(client.getState()).to.equal(state);
76 });
77 });
78
79 describe('router', function() {
80 var ctx, client;
81
82 beforeEach(function() {
83 client = new ClientApp();
84 client.fullPathName = function() { return ''; }
85
86 ctx = buildCtx('/');
87 });
88 });
89});