标签: teaspoon

angular mock`module`导致'[Object object]不是函数'

我正在尝试使用通过Teaspoon运行的Jasmine在Angular中创建一些单元测试.测试正在运行,但是我有一个简单的测试只是为了测试是否存在失败的控制器.我有以下测试设置.

//= require spec_helper

require("angular");
require("angular-mocks");
var app = require("./app");


describe("My App", function() {

  describe("App Controllers", function() {

    beforeEach(module("app"))

    it("Should have created an application controller", inject(function($rootScope, $controller){
      var scope = $rootScope.$new();
      ctrl = $controller("ApplicationCtrl", { $scope: scope });
    }));

  })

})
Run Code Online (Sandbox Code Playgroud)

需要的语句由Browserify处理,它处理我的依赖项,但我也可以挂钩我用于规范助手的链接.

在我需要的应用程序内部

require("angular");
var controllers = require("./controllers");

var app = angular.module("app", [
  "app.controllers"
]);

exports.app = app;
Run Code Online (Sandbox Code Playgroud)

当我运行此测试时,我得到以下错误

Failure/Error: TypeError: '[object Object]' is not a function (evaluating 'module("aialerts")')
Run Code Online (Sandbox Code Playgroud)

我花了很长时间试图解决这个问题,但我不知道发生了什么.任何帮助赞赏.

angularjs teaspoon angular-mock

25
推荐指数
2
解决办法
1万
查看次数

rails teaspoon在引擎中测试不加载*_spec.js

我正在研究一种引擎(宝石),它有一些js代码需要测试,但似乎我无法让它工作.我已经按照维基文章设置了一个基本的例子,但我只是得到了0 examples, 0 failures.

完成的步骤:

  • 在gemspec文件中添加了s.add_development_dependency'teaspoon-jasmine'
  • 虚拟是spec/dummy
  • 投机/ teaspoon_env.rb:

    unless defined?(Rails)
      ENV["RAILS_ROOT"] = File.expand_path("../dummy", __FILE__)
      require File.expand_path("#{ENV["RAILS_ROOT"]}/config/environment", __FILE__)
    end
    
    Teaspoon.configure do |config|
       ...
       config.root = MyEngineName::Engine.root
       ...
    end
    
    Run Code Online (Sandbox Code Playgroud)
  • Rake文件:

    desc "Run the javascript specs"
    task :teaspoon => "app:teaspoon"
    
    Run Code Online (Sandbox Code Playgroud)
  • spec/javascripts/spec_helper.js(默认生成时)
  • 规格/ Java脚本/ example_spec.js:

    describe("My great feature", function() {
      it("Bang", () => {
        expect(true).toBe(false);
      });
    });
    
    Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试运行测试引擎时,我得到:

    $> teaspoon 
    Starting the Teaspoon server...
    Thin web server (v1.7.0 codename Dunder Mifflin)
    Maximum connections set to 1024
    Listening on 127.0.0.1:57036, …
Run Code Online (Sandbox Code Playgroud)

javascript rubygems rspec ruby-on-rails teaspoon

6
推荐指数
1
解决办法
403
查看次数

如何使用 Mocha Chai Sinon 检查元素是否存在?

我想知道如何通过 id 或 class 检查 UI 上的元素是否存在。我用的是茶匙摩卡、诗浓和柴。

我尝试了下一个但它不起作用:

expect($('my-id')).to.be.true;
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js chai teaspoon sinon-chai

2
推荐指数
1
解决办法
3480
查看次数