加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 错误:错误:在角度js中找不到模块?

发布时间:2020-12-17 16:56:05 所属栏目:安全 来源:网络整理
导读:我尝试使用量角器进行简单的app ..try测试?我安装了所有的东西.并且能够运行量角器给出的例子..我自己做这样的例子 Index.html .. !DOCTYPE htmlhtmlhead lang="en" meta charset="UTF-8" titleSuper/title script src="https://ajax.googleapis.com/ajax/l
我尝试使用量角器进行简单的app ..try测试?我安装了所有的东西.并且能够运行量角器给出的例子..我自己做这样的例子

Index.html ..

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Super</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script>
    <script src="app.js"></script>

</head>
<body ng-app ="app">
<div ui-view></div>
</body>
</html>

app.js

angular.module('app',['ui.router']).config(function($stateProvider,$urlRouterProvider){

    $urlRouterProvider.otherwise("/state1");
    //
    // Now set up the states
    $stateProvider
        .state('state1',{
            url: "/state1",templateUrl: "partial/state1.html",controller:function($scope){
                $scope.clikme=function(){
                    $scope.message="hello"
                }

            }
        })
})

example.spec.js

var indexFunction=require('/indexFunction');





describe('angularjs homepage',function() {
    var page =new indexFunction();
    beforeEach(function(){
        page.getUrl()
    })
  it('should greet the named user',function() {
      expect(page.getTitile()).toEqual('Super');

  });

    it('should update',function(){

        page.clickMethod();
        expect(page.getMessage()).toBe('hello')
    })
});

index.spec.js

function indexFunction(){
    this.button= element(by.id('clickme'))  ;
    this.message=element(by.binding('message'))  ;

    this.getUrl=function(){
        browser.get('http://localhost:63342/example/index.html');

    }

    this.getTitile=function(){
        return browser.getTitle();
    }

    this.getMessage=function(){
        return this.message.getText();
    }

    this.clickMethod=function(){
        this.button.click();
    }
}

module.exports=indexFunction

当我运行这个例子时,我收到了这个错误

[![MacBook-Pro:example naveenkumar$protractor conf.js
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
[launcher] Error: Error: Cannot find module '/indexFunction'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/naveenkumar/Desktop/example/example_spec.js:2:23)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:][1]][1]

enter image description here

更新

r: Error: Cannot find module '/index.spec'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)

解决方法

在example.spec.js中它应该是:

var indexFunction = require('./index.spec');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读