javascript - 开始安装 Karma 和 Jasmine - jasmine.Suite() 需要错误

标签 javascript unit-testing resharper jasmine karma-runner

我正在尝试开始使用 karma 和 Jasmine 。

我已经安装了它们。我相信 Karma 可以找到我的 JavaScript 文件。当我运行 karma start 时,我的浏览器打开并显示:

Karma v0.12.23 - connected
IE 11.0.0 (Windows 8.1) is idle
Firefox 29.0.0 (Windows 8.1) is idle
Chrome 37.0.2062 (Windows 8.1) is idle

我将一个 JavaScript 文件添加到我认为 Karma 正在监视的位置:

it('y should have a length of 1', function () {
    var y = '1';
    expect(y.length).toBe(0);
});

我在哪里可以看到单元测试失败?

如果我在 vs2013 中打开 resharper,我会看到单元测试。当我去运行它时,一个新的浏览器窗口打开,它是空白的。控制台确实显示在此页面上:

ncaught Error: jasmine.Suite() required 

我怎样才能让它接受我的考试?

最佳答案

如 Jasmine 命名法 a suite 中所述

Suites: describe Your Tests

A test suite begins with a call to the global Jasmine function describe with two parameters: a string and a function. The string is a name or title for a spec suite – usually what is being tested. The function is a block of code that implements the suite.

所以我想您必须将测试包装在 describe 语句

describe('my test suite',function(){
    
    it('my test case',function(){
        //some assertions
    })
});

关于javascript - 开始安装 Karma 和 Jasmine - jasmine.Suite() 需要错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26051001/

相关文章:

javascript - HTML 和 JavaScript 的执行顺序是什么?

c# - 单元测试丰富的领域模型

visual-studio - 在 Visual Studio + ReSharper 中导航到文件的特殊行

c# - 无法在 Visual Studio 中键入

asp.net-mvc - ReSharper 5.0 窒息位于同一项目中的强类型 View 模型

javascript - 将react/node应用程序部署到heroku时出现webpack-dev-server错误

javascript - Highcharts,具有共享图例项的多堆叠条

javascript - 在 JavaScript 中使用日期时如何强制英国夏令时 (UTC+1)?

silverlight - 运行 Silverlight 单元测试时出现 NullReferenceException

java - 将 @ShouldMatchDataSet 与 NoSQLUnit 一起使用时,有什么方法可以忽略某些字段吗?