尝试使用Karma为Typescript项目设置单元测试 [英] Trying to setup unit testing for Typescript project using Karma

查看:592
本文介绍了尝试使用Karma为Typescript项目设置单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Karma测试用Typescript编写的NodeJS项目.我想使用tsUnit作为单元测试框架

I am trying to use Karma to test a NodeJS project written in Typescript. I want to use tsUnit as the Unit test framework

http://tsunit.codeplex.com/

和karma-typescript-preprocessor使karma首先编译打字稿.

and the karma-typescript-preprocessor to get karma to compile typescript first.

https://npmjs.org/package/karma-typescript-preprocessor

这真是一个非常坎bump的旅程,我很想了解任何有经验的人,可以设置Karma来通过NodeJS测试Typescript.即使您使用了其他测试框架或预处理器.

This is turning out to be a very bumpy ride and I would love to understand the process from anyone who has experience setting up Karma to test Typescript over NodeJS. Even if you have used a different test framework or preprocessor.

推荐答案

我只是设置了Karma/Typescript测试,但未使用Node.js.我使用的是Intellij Idea 13和Karma插件,在这里按照以下过程进行操作:

I just set up a Karma/Typescript test but it's not using Node.js. I'm using Intellij Idea 13 and the Karma plugin, and I followed this process here:

http://www.youtube.com/watch?v=4CgKU7jTub4

基本步骤是:

  1. 设置观察程序以在保存文件时编译您的Typescript文件.
  2. 使用Karma初始化karma.conf.js设置Karma设置(我使用的是Chrome/Jasmine)
  3. 将您的js文件添加到文件列表中,以确保它们已包含在测试中.
  4. 下载Jasmine/Jasmine-Jquery的Typescript定义作为全局库.

并不太痛苦,Webstorm在整个操作中添加了一个不错的GUI.

It wasn't too painful, and Webstorm adds a nice GUI to the whole operation.

这篇关于尝试使用Karma为Typescript项目设置单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆