Skip to content

Commit 4b28bf9

Browse files
Ported tests to typescript
Added chai assertions to karma Fixed tsconfig to comply with recommended Vue configs
1 parent 9077eb1 commit 4b28bf9

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

template/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"vue": "^2.1.0"
1616
},
1717
"devDependencies": {
18+
"@types/chai": "^3.4.35",
19+
"@types/mocha": "^2.2.40",
1820
"autoprefixer": "^6.4.0",
21+
"chai": "^3.5.0",
1922
"chalk": "^1.1.3",
2023
"connect-history-api-fallback": "^1.1.0",
2124
"css-loader": "^0.28.0",
@@ -33,6 +36,7 @@
3336
"istanbul-instrumenter-loader": "^2.0.0",
3437
"json-loader": "^0.5.4",
3538
"karma": "^1.4.1",
39+
"karma-chai": "^0.1.0",
3640
"karma-coverage-istanbul-reporter": "^1.0.0",
3741
"karma-mocha": "^1.3.0",
3842
"karma-phantomjs-launcher": "^1.0.2",

template/test/unit/init.test.js

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

template/test/unit/karma.conf.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
var webpackConfig = require('../../build/webpack.dev.conf')
66
var path = require('path');
77

8-
module.exports = function (config) {
8+
module.exports = function(config) {
99
config.set({
1010
// to run in additional browsers:
1111
// 1. install corresponding karma launcher
1212
// http://karma-runner.github.io/0.13/config/browsers.html
1313
// 2. add it to the `browsers` array below.
1414

1515
browsers: ['PhantomJS'],
16-
frameworks: ['mocha'],
16+
frameworks: ['mocha', 'chai'],
1717
reporters: ['spec', 'coverage-istanbul'],
1818

19-
files: ['./init.test.js'],
19+
files: ["spec/**/*.ts"],
2020
preprocessors: {
21-
'./init.test.js': ['webpack']
21+
"spec/**/*.ts": ['webpack']
2222
},
23+
//files: ['./init.test.js'],
24+
//preprocessors: {
25+
// './init.test.js': ['webpack']
26+
//},
2327
webpack: webpackConfig,
2428
webpackMiddleware: {
2529
noInfo: true

template/test/unit/spec/SideNav.spec.js renamed to template/test/unit/spec/SideNav.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import SideNav from 'components/SideNav'
3-
import assert from "assert";
3+
import "chai";
4+
const assert = chai.assert;
45

56
describe('SideNav.vue', function () {
67
beforeEach(function () {
@@ -26,7 +27,7 @@ describe('SideNav.vue', function () {
2627

2728
// The only child is the 'Toggle Links' item
2829
assert.equal(vm.$el.children.length, 1);
29-
vm.$el.children[0].click();
30+
(vm.$el.children[0] as HTMLElement).click();
3031

3132
Vue.nextTick(function() {
3233
// There are 3 links + 1 toggle link item.
@@ -41,11 +42,11 @@ describe('SideNav.vue', function () {
4142

4243
// The only child is the 'Toggle Links' item
4344
assert.equal(vm.$el.children.length, 1);
44-
vm.$el.children[0].click();
45+
(vm.$el.children[0] as HTMLElement).click();
4546

4647
Vue.nextTick(function() {
4748
assert.equal(vm.$el.children.length, 4);
48-
vm.$el.children[0].click();
49+
(vm.$el.children[0] as HTMLElement).click();
4950

5051
Vue.nextTick(function() {
5152
// Clicking it again should hide all links

template/test/unit/spec/WinnerIsYou.spec.js renamed to template/test/unit/spec/WinnerIsYou.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import WinnerIsYou from 'components/WinnerIsYou'
3-
import assert from "assert";
3+
import "chai";
4+
const assert = chai.assert;
45

56
describe('WinnerIsYou.vue', function () {
67

template/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4+
"allowSyntheticDefaultImports": true,
45
"lib": ["es5", "es2015.promise", "dom"],
56
"experimentalDecorators": true,
6-
"sourceMap": true
7+
"sourceMap": true,
8+
"module": "es2015",
9+
"moduleResolution": "node"
710
},
811
"files": [
912
"./src/main.ts"

0 commit comments

Comments
 (0)