繁体   English   中英

Jasmine期望不使用requirejs

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM