我有一个templateUrl定义的AngularJS指令.我正在尝试用Jasmine进行单元测试.
根据以下建议,我的Jasmine JavaScript如下所示:
describe('module: my.module', function () {
beforeEach(module('my.module'));
describe('my-directive directive', function () {
var scope, $compile;
beforeEach(inject(function (_$rootScope_, _$compile_, $injector) {
scope = _$rootScope_;
$compile = _$compile_;
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('path/to/template.html').passThrough();
}));
describe('test', function () {
var element;
beforeEach(function () {
element = $compile(
'<my-directive></my-directive>')(scope);
angular.element(document.body).append(element);
});
afterEach(function () {
element.remove();
});
it('test', function () {
expect(element.html()).toBe('asdf');
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
当我在我的Jasmine规范错误中运行它时,我收到以下错误:
TypeError: Object #<Object> has no method 'passThrough'
Run Code Online (Sandbox Code Playgroud)
我想要的是模板加载原型 - 我不想使用respond.我相信这可能与使用ngMock …
我在我的应用程序上使用grunt运行了业力,但由于某种原因,事情停止了工作.我通过重新安装更新了业力,这改变了很多,并更改了我的配置文件.我的所有文件都被添加和提供,但是它没有执行我的任何测试.
暂时(只是试图让事情再次运行),我正在使用命令在grunt之外运行karma start <pathtomyconfigfile>.使用LOG_DEBUG选项,我看到所有添加和服务.
这是我的配置文件:
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'../build/angular/angular.js',
'../build/angular/angular-mocks.js',
'../build/angular/angular-resource.js',
'../build/angular/angular-cookies.js',
'../build/angular/angular-scenario.js',
'../src/**/*.js',
'../dist/tmp/**/*.js',
'../vendor/angular-bootstrap/*.js',
'../vendor/angular-ui-utils/modules/route/*.js',
'../vendor/angular-ui-utils/modules/mask/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: …Run Code Online (Sandbox Code Playgroud) 在过去的两个小时里,我一直在尝试让Karma跑步者服务svg文件和html夹具,但到目前为止还没有运气.
关于这个帖子的第二个答案:将html与testacularjs集成时出错我一直试图served用来表示我的fixtures和svg文件应该由服务器分发,但我仍然得到'找不到'
files = [
JASMINE,
JASMINE_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
// put all components in requirejs 'paths' config here (included: false)
{ pattern: 'preview/public/components/**/*.js', included: false },
{ pattern: 'preview/public/js/**/*.js', included: false },
// assets
{ pattern: 'preview/public/img/svg/*.svg', included: false, served: true },
// helpers & fixtures for jasmine-jquery
{ pattern: 'test/libs/**/*.js', included: true },
{ pattern: 'test/fixtures/**/*.html', included: false, served: true },
// all src and test modules (included: false)
{ pattern: 'test/specs/**/*.spec.js', included: false }, …Run Code Online (Sandbox Code Playgroud)