【问题标题】:Global teardown function in Jasmine.jsJasmine.js 中的全局拆解功能
【发布时间】:2014-07-16 16:53:42
【问题描述】:

我正在使用 Jasmine 测试 Rails 4 / ember.js 应用程序。

如何在每个规范之后重置 Ember,而不将拆解写入每个规范文件?

# Spec/javascript/support/spec_helper.js.coffee

App.ApplicationAdapter = DS.FixtureAdapter
App.setupForTesting()
App.injectTestHelpers()

# Reset Ember after each spec
# How do I tell jasmine to run a function after each spec?
# Metacode:
jasmine.afterEach ->
    App.reset()

【问题讨论】:

  • 用coffeescript编写的javascript问题

标签: ember.js coffeescript jasmine


【解决方案1】:

beforeEach/afterEach 也可以全局声明,只需使用

beforeEach(function() {
  console.log('before');
});

afterEach(function() {
  console.log('after');
});

这是一个全局实现的例子(不是 Ember)。

http://jsbin.com/pavokiru/1/edit

我个人会将 qunit 与 Ember 一起使用,他们已经构建了许多用于 qunit 的助手,要使其与 jasmine 一起使用需要做很多工作,尤其是在涉及异步进程时(其中很多余烬)。

【讨论】:

    猜你喜欢
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 2015-11-10
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多