Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 3b4d28e

Browse files
committed
added some unit tests
1 parent 9231d7b commit 3b4d28e

File tree

7 files changed

+78
-24
lines changed

7 files changed

+78
-24
lines changed

js/router.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Router } from 'backbone';
2-
import $ from 'jquery';
32

43
export default class ObRouter extends Router {
54
constructor() {
@@ -12,7 +11,5 @@ export default class ObRouter extends Router {
1211
];
1312

1413
routes.forEach((route) => this.route.apply(this, route));
15-
16-
this.$obContainer = $('#obContainer');
1714
}
1815
}

js/utils/Dog.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"sass:build": "node-sass --source-map true --include-path styles styles/main.scss .tmp/styles/main.css",
1414
"sass:watch": "nodemon -e scss -x \"npm run sass:build\"",
1515
"index:watch": "nodemon -w index.html -x \"npm run process-index\"",
16-
"browsersync": "browser-sync start --no-ui -f 'js,.tmp/**/*.css,.tmp/**/*.html'",
16+
"browsersync": "browser-sync start --no-ui -f 'js, .tmp/**/*.css, .tmp/**/*.html, !.tmp/test/**/*'",
1717
"process-index": "cross-env NODE_ENV=development babel-node ./bin/processIndex.js"
1818
},
1919
"repository": {

test/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rules":{
3+
// mocha discourages passing in arrow functions as callbacks
4+
"prefer-arrow-callback": 0,
5+
"func-names": 0
6+
}
7+
}

test/utils/dog.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/utils/loadTemplate.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { expect } from 'chai';
2+
import { describe, it, before, after } from 'mocha';
3+
import fs from 'fs';
4+
import path from 'path';
5+
import loadTemplate from '../../js/utils/loadTemplate';
6+
7+
const dummyTemplatePath = path.join(__dirname, '../../.tmp/test');
8+
const dummyTemplatePathFromRoot = '.tmp/test';
9+
const dummyTemplateFile = 'test.html';
10+
const dummyTemplateContents = 'my name is <%= ob.name %>';
11+
12+
describe('loading a template', () => {
13+
before(function () {
14+
if (!fs.existsSync(dummyTemplatePath)) {
15+
fs.mkdirSync(dummyTemplatePath);
16+
}
17+
18+
fs.writeFileSync(path.join(dummyTemplatePath, dummyTemplateFile), dummyTemplateContents);
19+
});
20+
21+
// first time we load a template, it retrieves it from the file-system
22+
// and returns a compiled template
23+
it('for the first time, reads the template from the file system', () => {
24+
let output;
25+
26+
loadTemplate(path.join(dummyTemplatePathFromRoot, dummyTemplateFile), (t) => {
27+
output = t({ name: 'billy' });
28+
}, './');
29+
30+
expect(output).to.equal('my name is billy');
31+
});
32+
33+
// After the first time we load a template, subsequent requests do not
34+
// go to the file system. Instead, a cached, compiled template is returned.
35+
it('after the first time, returns a cached template', () => {
36+
let output;
37+
38+
fs.writeFileSync(path.join(dummyTemplatePath, dummyTemplateFile),
39+
`${dummyTemplateContents} updated!!!`);
40+
41+
loadTemplate(path.join(dummyTemplatePathFromRoot, dummyTemplateFile), (t) => {
42+
output = t({ name: 'billy' });
43+
});
44+
45+
expect(output).to.equal('my name is billy');
46+
});
47+
48+
after(function () {
49+
fs.unlinkSync(path.join(dummyTemplatePath, dummyTemplateFile));
50+
});
51+
});
52+

test/utils/platform.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import * as platform from '../../js/utils/platform';
4+
5+
describe('platform', () => {
6+
it('correctly identifies whether I\'m on a mac', () => {
7+
expect(platform.isMac()).to.equal(process.platform === 'darwin');
8+
});
9+
10+
it('correctly identifies whether my platform is Windows', () => {
11+
expect(platform.isWin()).to.equal(process.platform === 'linux');
12+
});
13+
14+
it('correctly identifies whether my platform is Linux', () => {
15+
expect(platform.isLinux()).to.equal(process.platform === 'win32');
16+
});
17+
});
18+

0 commit comments

Comments
 (0)