2016-06-07 32 views
0

我一直在爲我當前的角度項目編寫幾十個量角器測試,它們都工作。量角器無法讀取未定義的屬性'超時'

我貼試驗,以創建一組新的測試,並注意到,如果有直接嵌套在另一個describe一個describe,我得到一個錯誤Cannot read property 'timeout' of undefined和量角器與代碼100

退出。如果我刪除嵌套describe,它馬上工作。

如果在嵌套describe之前有一個it,那麼這樣做......所有這一切對我來說都非常奇怪。

下面是測試和錯誤:

代碼:

/* eslint max-len: 0 */ 
/* eslint-env es6 */ 
'use strict'; 

var chai = require('chai'); 
var expect = chai.expect; 
var chaiAsPromised = require('chai-as-promised'); 
var config = require('../../../../gulp/config'); 

chai.use(chaiAsPromised); 

describe('Compléter la reception de l\'offre d\'acquisition', function describe() { 
    var localhost = config.e2e.localhost; 

    this.timeout(15000); 

    describe('View mode:', function() { 
    it('Should redirect the user to the /tableauoffre page when clicking on "Quitter"', function it() { 
     browser.get('/tableauoffre'); 

     browser.waitForAngular() 
     .then(function getFirstRow() { 
      return element(by.id('table-0')) 
      .all(by.css('tbody tr')) 
      .get(0); 
     }) 
     .then(function click(row) { 
      return row 
      .all(by.css('a')) 
      .get(0) 
      .click(); 
     }) 
     .then(function redirect() { 
      return browser.getCurrentUrl(); 
     }) 
     .then(function click() { 
      return element(by.id('quitter-btn')) 
      .click(); 
     }) 
     .then(function url() { 
      return browser.getCurrentUrl(); 
     }) 
     .then(function test(url) { 
      expect(url).to.equal(`${localhost}/tableauoffre`); 
     }); 
    }); 
    }); 
}); 

錯誤:

[11:21:24] Starting 'protractor'... 
Using ChromeDriver directly... 
[launcher] Running 1 instances of WebDriver 
[launcher] Error: TypeError: Cannot read property 'timeout' of undefined 
    at describe (/Users/[user-name]/Documents/banq/trunk/app/modules/views/assigner.offre/assigner.offre.e2e.js:15:7) 
    at Suite.describe (/Users/[user-name]/Documents/banq/trunk/app/modules/views/assigner.offre/assigner.offre.e2e.js:21:3) 
    at context.describe.context.context (/Users/[user-name]/Documents/banq/trunk/node_modules/mocha/lib/interfaces/bdd.js:47:10) 
    at Object.<anonymous> (/Users/[user-name]/Documents/banq/trunk/app/modules/views/assigner.offre/assigner.offre.e2e.js:12:1) 
    at Module._compile (module.js:409:26) 
    at Object.Module._extensions..js (module.js:416:10) 
    at Module.load (module.js:343:32) 
    at Function.Module._load (module.js:300:12) 
    at Module.require (module.js:353:17) 
    at require (internal/module.js:12:17) 
[launcher] Process exited with error code 100 

/Users/[user-name]/Documents/banq/trunk/gulp/tasks/protractor.js:24 
     throw err; 
    ^
Error: protractor exited with code 100 
    at ChildProcess.<anonymous> (/Users/[user-name]/Documents/banq/trunk/node_modules/gulp-protractor/index.js:63:27) 
    at emitTwo (events.js:87:13) 
    at ChildProcess.emit (events.js:172:7) 
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12) 
+0

爲什麼你甚至嵌套描述任何特定的原因? –

+0

我嵌套以分離一個視圖的2個版本:編輯和查看模式。也就是說,它支持這樣做,所以爲什麼不應該太重要,除非我打破了一個不成文的規則 – justinledouxweb

回答

0

只是一個想法...嘗試

var self = this; 
self.timeout(15000); 

我不也不理解你的問題,但是我只是想嘗試一下。無論如何,將this存儲到一個變量中是一個好方法,至少在您打算繼續使用它的時候。

超時的目的是什麼?

+0

它不起作用,因爲錯誤說'timeout'不在'this'上,所以它贏得'如果我不使用超時,我的測試將隨機失敗,因爲它們超時,即使我增加了配置文件中的超時時間。 – justinledouxweb

0

好的,所以我發現命名你的回調函數,並使用一個函數名稱相同的函數實際上混淆了事情,因此爲什麼this沒有正確的屬性。

因此,請務必使用唯一的名稱爲您調用回調函數。

相關問題