2017-06-15 118 views
1

我的測試是從命令行傳遞的,但是我使用Atom編輯typescript源。不能分配給編輯器中的'預期<Promise <string>>'參數

而當我在編輯器中打開該測試文件中的一個,我在這條線時看到錯誤:

expect(pageObject.name.getText()).toEqual('Some name'); 

這是錯誤:

Typescript 

Error 
Argument of type '"Some name"' is not assignable to parameter of type 'Expected<Promise<string>>'.at line 16 col 50 

爲什麼這個節目在我的編輯器中?但測試通過。從package.json

"dependencies": { 
    "typescript": "2.3.3" 
}, 
"devDependencies": { 
    "@types/jasmine": "2.5.45", 
    "@types/node": "^7.0.13", 
    "jasmine-core": "^2.6.0", 
    "jasmine-spec-reporter": "^4.1.0", 
    "protractor": "^5.1.2" 
} 

tsconfig.fvt.test.json

{ 
    "compilerOptions": { 
    "module": "commonjs", 
    "noImplicitAny": true, 
    "noUnusedLocals": true, 
    "moduleResolution": "node", 
    "sourceMap": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "noUnusedParameters": true, 
    "outDir": "dist", 
    "skipLibCheck": true, 
    "target": "ES5", 
    "lib": [ 
     "dom", "es5", "es6", "scripthost" 
    ], 
    "types": ["jasmine"] 
    }, 
    "include": [ 
    "protractor.config.ts", 
    "test/e2e/**/*.ts" 
    ] 
} 
+0

Atom TypeScript模塊嘗試從'tsconfig.json'讀取其配置。檢查你的'tsconfig.json'和你的'tsconfig.fvt.test.json'文件是否有區別。 –

+0

'pageObject.name.getText()'是一個承諾,所以我不驚訝這個消息顯示出來,儘管我不知道'tsconfig.json'是否可以解決這個問題。你也可以首先解決promise,然後做比較,或像這樣使用'async/await' expect(等待pageObject.name.getText())。toEqual('Some name');' – wswebcreation

回答

1

getText()回報承諾

protractor dist/protractor.config.js 

段:

命令運行量角器測試。請參閱doc

如果你想斷言一個元素的文本,你需要chai-as-promise。 見example

相關問題