茉莉花2.0异步beforeEach不等待异步完成

编程入门 行业动态 更新时间:2024-10-25 04:21:41
本文介绍了茉莉花2.0异步beforeEach不等待异步完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是用茉莉花2.0和require.js。我不能当我把异步code在beforeEach功能异步测试正常工作。我这语句是异步调用完成之前仍在运行。

I am using Jasmine 2.0 and require.js. I cannot get the async tests to work properly when I put the async code in a beforeEach function. My it statement is still running before the async call finishes.

下面是我的规格:

describe("App Model :: ", function() { var AppModel; beforeEach(function(done) { require(['models/appModel'], function(AppModel) { AppModel = AppModel; done(); }); }); // THIS SPEC FAILS AND RUNS BEFORE ASYNC CALL it("should exist", function(done) { this.appModel = new AppModel() expect(this.appModel).toBeDefined(); done(); }); // THIS SPEC PASSES it("should still exist", function(done) { require(['models/appModel'], function(AppModel) { this.appModel2 = new AppModel() expect(this.appModel2).toBeDefined(); done(); }); }); });

第一规格失败,但第二个规格的推移,当我包括在是异步。

在理想情况下,我想在 beforeEach 异步工作而不是不干燥和复制均需要到各个它的声明。

Ideally, I'd like the beforeEach async to work rather than being not DRY and copying each require into the individual it statements.

任何提示?

推荐答案

本地需要VAR应该有另外一个名字被包装的范围之外。此外,在它你不需要做的,它仅在异步部分。像这样的东西必须工作:

Local require var should have another name to be wrapped to the outside scope. Also in the "it" you do not require done, it is only in the async part. Something like this must work:

describe("App Model :: ", function() { var AppModel; beforeEach(function(done) { require(['models/appModel'], function(_AppModel) { AppModel = _AppModel; done(); }); }); it("should exist", function() { var appModel = new AppModel() expect(appModel).toBeDefined(); }); });

更多推荐

茉莉花2.0异步beforeEach不等待异步完成

本文发布于:2023-11-10 22:46:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576671.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:茉莉花   beforeEach

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!