[英]Jasmine expect not working with requirejs
以下代碼永遠不會運行:
define("model/Contact", function() {
console.log(Contact);
describe('Something',function(){
it('shows no error',function(){
require(["model/MyModel"], function(MyModel) {
console.log(MyModel);
expect(false).toBeTruthy();
});
});
});
});
如果我使用define塊,代碼永遠不會在jasmine maven插件中運行: http : //searls.github.io/jasmine-maven-plugin/amd-support.html
我的插件
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.3.1.2</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
<jsSrcDir>${jsFolder}/src</jsSrcDir>
<jsTestSrcDir>${jsTestFolder}/specs</jsTestSrcDir>
<preloadSources>
<source>${jsFolder}/src/extlib/requirejs/require.js</source>
</preloadSources>
</configuration>
</plugin>
有趣的是以下代碼:
describe('Something',function(){
it('shows no error',function(){
require(["model/MyModel"], function(MyModel) {
console.log(MyModel);
expect(false).toBeTruthy();
});
});
});
如果我使用此代碼,則MyModel已定義並可用。 但expect()函數永遠不會拋出錯誤。
我做錯了什么?
在開始測試之前,您必須要求您的模塊:
require(["model/MyModel"], function (MyModel) {
describe('Something', function () {
it('shows no error', function () {
console.log(MyModel);
expect(false).toBeTruthy();
});
});
});
在您的示例中,測試運行器在require回調運行之前完成了測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.