使用新的Visual Studio 2017 Angular模板,如何添加Jasmine测试 [英] Using the new Visual Studio 2017 Angular template, how do I add Jasmine tests

查看:304
本文介绍了使用新的Visual Studio 2017 Angular模板,如何添加Jasmine测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的Visual Studio 2017 ASP.Net Core Angular模板
https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page -applications-on-asp-net-core-with-javascriptservices /
我的小应用程序已创建,现在我想添加一些测试。我无法看到如何运行我的第一个Jasmine测试 - 正确引用相关库(vendor.js(?)等)。

I'm using the new Visual Studio 2017 ASP.Net Core Angular template https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/ My small application is created and I now want to add some tests. I can't see how to get my first Jasmine test running - correctly referencing the relevant libraries (vendor.js (?) etc).

=====

仍然没有,但是出现了。从.Net背景与单独项目中的测试到测试代码,我没有意识到spec文件将与他们正在测试的代码位于同一文件夹中 - 现在我有了counter.component.spec.ts。我还没有设法运行那些测试:根据R.Richards解决方案的评论,通过cmd行我得到Webpack not found错误;通过Resharper,Chrome打开时显示未找到规格,Resharper在每次测试时都说超时时跳过任务。

Still not there, but coming along. From a .Net background with tests in separate projects to tested code, I didn't realise spec files would sit in the same folder as the code they are testing - now I've got counter.component.spec.ts. I haven't managed to run those tests yet: as per the comment on R.Richards solution, via cmd line I get the Webpack not found error; via Resharper, Chrome opens with "No specs found" and Resharper says "Task skipped on timeout" for each test.

推荐答案

首先,在.Net / Angular项目所在的目录( .csproj 文件所在的目录)中打开命令提示符。

First, open a command prompt in the directory where the .Net/Angular project is (the directory where the .csproj file is located).

运行此命令:

karma start .\ClientApp\test\karma.conf.js 

如果您收到有关业力不是已知应用程序的错误,请运行此命令:

If you get an error about karma not being a known application, then run this:

npm i -g karma

此命令全局安装karma,因此您可以在安装它的计算机上的任何位置从命令提示符运行它。

This command installs karma globally, so you can run it from the command prompt anywhere on the machine you install it.

现在再次重新运行 karma start 命令。

Now rerun the karma start command again.

karma start 命令运行karma,这是一个测试运行器。它将使用 karma.conf.js 文件在项目中查找,编译和运行单元测试。

The karma start command runs karma, which is a test runner. It will use the karma.conf.js file to look for, compile, and run unit tests in the project.

VS 2017 Angular模板附带一个已编写的规范(Jasmine框架单元测试)文件,该文件位于 ClientApp \ app \components\counter 文件夹中,所以你应该看到2个测试成功运行,除非你从项目中删除了spec文件,或者改变了应用程序足以打破它们。

The VS 2017 Angular template comes with one spec (Jasmine framework unit tests) file already written, which is in the ClientApp\app\components\counter folder, so you should see 2 tests run successfully, unless you have removed the spec file from the project, or changed the application enough to break them.

那个如何运行Typescript /使用VS 2017 Angular模板进行基于JavaScript的单元测试。

That how to run Typescript/JavaScript based unit tests with the VS 2017 Angular template.

这篇关于使用新的Visual Studio 2017 Angular模板,如何添加Jasmine测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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