Skip to content

Commit 5221920

Browse files
committed
Add basic sanity tests for the routes.
1 parent 95b962f commit 5221920

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

test/browser/index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { h, render, rerender } from 'preact';
2+
import { route } from 'preact-router';
3+
import App from 'components/app';
4+
import 'style';
5+
6+
/*global sinon,expect*/
7+
8+
describe('App', () => {
9+
let scratch;
10+
11+
before( () => {
12+
scratch = document.createElement('div');
13+
(document.body || document.documentElement).appendChild(scratch);
14+
});
15+
16+
beforeEach( () => {
17+
scratch.innerHTML = '';
18+
});
19+
20+
after( () => {
21+
scratch.parentNode.removeChild(scratch);
22+
scratch = null;
23+
});
24+
25+
26+
describe('routing', () => {
27+
it('should render the homepage', () => {
28+
render(<App />, scratch);
29+
30+
expect(scratch.innerHTML).to.contain('Home');
31+
});
32+
33+
it('should render /profile', () => {
34+
render(<App />, scratch);
35+
route('/profile');
36+
rerender();
37+
38+
expect(scratch.innerHTML).to.contain('Profile: me');
39+
});
40+
41+
it('should render /profile/:user', () => {
42+
render(<App />, scratch);
43+
route('/profile/john');
44+
rerender();
45+
46+
expect(scratch.innerHTML).to.contain('Profile: john');
47+
});
48+
});
49+
});

test/karma.conf.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require('babel-register');
2+
var webpack = require('../webpack.config.babel.js');
3+
4+
module.exports = function(config) {
5+
config.set({
6+
basePath: '../',
7+
frameworks: ['mocha', 'chai-sinon'],
8+
reporters: ['mocha'],
9+
10+
browsers: ['PhantomJS'],
11+
12+
files: [
13+
'test/browser/**/*.js'
14+
],
15+
16+
preprocessors: {
17+
'test/**/*.js': ['webpack'],
18+
'src/**/*.js': ['webpack'],
19+
'**/*.js': ['sourcemap']
20+
},
21+
22+
webpack: webpack,
23+
webpackMiddleware: { noInfo: true }
24+
});
25+
};

0 commit comments

Comments
 (0)