简体   繁体   English

使用Angular JS进行茉莉花测试

[英]Jasmine Testing with Angular JS

I've included jasmine in an angular project and I'm trying to hook up a spec file to a file that has my angular controllers (so I can do unit tests). 我已将Jasmine包含在角度项目中,并且试图将规格文件连接到具有角度控制器的文件中(以便可以进行单元测试)。 The problem is that I'm not entirely sure how to wire this up. 问题是我不确定如何将其连接起来。

This is what the folder hierarchy for my project looks like: 这是我的项目的文件夹层次结构:

project_folder/index.html
project_folder/js/controllers.js
project_folder/lib/jasmine/jasmine-standalone-2.3.4/spec/challengeSpec.js

Currently I want the tests for the controllers.js file (with the Angular code) to be in the challengeSpec.js file. 目前,我希望controllers.js文件(带有Angular代码)的测试位于ChallengeSpec.js文件中。 How can I bring in the modules from the controllers.js file and use them in my tests? 如何从controllers.js文件中引入模块并在测试中使用它们? This is what some of the code from each of the files looks like: 这是每个文件中的一些代码如下所示:

controllers.js file:

var siteControllers = angular.module('siteControllers', []);
    fibonacciControllers.controller('pageController', ['$scope','$http', function ($scope, $http) {
    ...
});

challengeSpec.js file:

describe('siteControllers', function() {
    beforeEach(module('siteControllers'));
});

I know in the challengeSpec.js file I need to bring in the modules from the controllers.js file, but I'm not sure how this can be done. 我知道在ChallengeSpec.js文件中我需要从controllers.js文件中引入模块,但是我不确定如何做到这一点。 I've been doing some research that suggests I use Karma, but I'm not quite sure how this fits into the equation here. 我一直在做一些研究,建议我使用Karma,但我不确定这在这里是否适合方程式。 Thanks in advance. 提前致谢。

Your test spec seems to be on a good start, but you should not put the file in the place you did. 您的测试规范似乎是一个良好的开端,但您不应将文件放在原来的位置。 Using Karma is needed as it is the 'test runner'. 需要使用业力,因为它是“测试跑步者”。 For a completer story from az I'd try reading this https://www.airpair.com/angularjs/posts/unit-testing-angularjs 有关az的完整故事,请尝试阅读此https://www.airpair.com/angularjs/posts/unit-testing-angularjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM