简体   繁体   中英

angularjs e2e test, no result

When I ran SpecRunning, the web page showed nothing, but there wasn't any error. This is my SpecRunning.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jasmine Spec Runner v<%= jasmineVersion %></title>

<link rel="shortcut icon" type="image/png" href="test/images/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="test/lib/jasmine-core/jasmine.css">

<script type="text/javascript" src="test/lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="test/lib/jasmine-core/jasmine-html.js"></script>
<script type="text/javascript" src="test/lib/jasmine-core/boot.js"></script>
<script type="text/javascript" src="app/lib/angular/angular-scenario.js"></script>

<!-- include source files here... -->
<script src="app/js/phoneControllers.js"></script>

<!-- include spec files here... -->
<script src="test/js/phoneControllersSpec.js"></script>
</head>
<body></body>
</html>

This is

phoneControllers.js

function PhoneListCtrl($scope){
$scope.phones=[
    {
        "name":"SamSung",
        "snippet":"Good phone"
    },
    {
        "name":"M",
        "snippet":"Small phone"
    },
    {
        "name":"Apple",
        "snippet":"American phone"
    },
    {
        "name":"BBK",
        "snippet":"Made in China"
    }
];

$scope.Hello="Hello,world";
}

describe("PhoneCat controllers", function(){
describe("PhoneListCtrl", function(){
    var scope={}, ctrl=new PhoneListCtrl(scope);
    it("should create 'phones' model with 4 phones", function(){
        expect(scope.phones.length).toBe(4);
    });

    it("should create 'Hello,world' sentence", function(){
        expect(scope.Hello).toEqual("Hello,world");
    });
});
});

This is my phoneControllersSpec.js

describe('PhoneCat App', function(){
describe('Phone list view', function(){
    beforeEach(function(){
        browser().navigateTo('../../app/Index.html');
    });

    it('should filter ', function(){
        expect(repeater('.phones li').count()).toBe(4);

        input('query').enter('SamSung');
        expect(repeater('.phones li').count()).toBe(1);

        input('query').enter('China');
        expect(repeater('.phones li').count()).toBe(1);
    });
    });
});

If I remove

<script type="text/javascript" src="app/lib/angular/angular-scenario.js"></script>

from SpecRunning.html, it prompted "browser is not defined". What should I do? Thanks in advance

Afterwards I resolved this by myself.

  1. We should write test file in a separate html file
  2. We should make sure the js path is right

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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