2017-06-08 46 views
1

在使用npm測試的Visual Studio代碼中運行量角器測試時,出現如下錯誤,好像是node_modules/@types/jasmine/index.d.ts問題,如何擺脫這個錯誤?運行量角器打字稿時npm測試時拋出錯誤

C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test>npm test 

> [email protected] pretest C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test 
> npm run tsc 


> [email protected] tsc C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test 
> tsc 

node_modules/@types/jasmine/index.d.ts(26,41): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 
node_modules/@types/jasmine/index.d.ts(27,39): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 
node_modules/@types/jasmine/index.d.ts(152,24): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 

node_modules/@types/jasmine/index.d.ts(334,14): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 

node_modules/@types/jasmine/index.d.ts(435,24): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 

node_modules/@types/jasmine/index.d.ts(448,30): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 
node_modules/@types/jasmine/index.d.ts(448,30): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s). 

node_modules/@types/jasminewd2/index.d.ts(23,13): error TS2428: All declarations of 'Matchers' must have identical ty 
pe parameters. 
node_modules/@types/jasminewd2/index.d.ts(47,13): error TS2430: Interface 'ArrayLikeMatchers<T>' incorrectly extends 
interface 'Matchers<ArrayLike<T>>'. 
    Types of property 'toBe' are incompatible. 
    Type '(expected: any, expectationFailOutput?: any) => Promise<void>' is not assignable to type '{ (expected: any, 
expectationFailOutput?: any): boolean; (expected: any, expectationFailOutput?: ...'. 
     Type 'Promise<void>' is not assignable to type 'boolean'. 
node_modules/@types/jasminewd2/index.d.ts(48,20): error TS2304: Cannot find name 'Expected'. 
node_modules/@types/jasminewd2/index.d.ts(49,23): error TS2304: Cannot find name 'Expected'. 

npm ERR! Windows_NT 6.1.7601 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" " 
run" "tsc" 
npm ERR! node v6.10.3 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] tsc: `tsc` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] tsc script 'tsc'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the example-typescript package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  tsc 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs example-typescript 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls example-typescript 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test\npm-debug.log 
npm ERR! Test failed. See above for more details. 

C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test> 

以下是我已經習慣了在Visual Studio代碼打字稿和茉莉框架運行量角器

的package.json

{ 
    "name": "example-typescript", 
    "version": "1.0.0", 
    "description": "a typescript example", 
    "author": "", 
    "license": "MIT", 
    "scripts": { 
    "tsc": "tsc", 
    "pretest": "npm run tsc", 
    "test": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor tmp/conf.js", 
    "debug": "node --inspect --debug-brk C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor asyncAwait/conf.js" 
    }, 
    "dependencies": { 
    "@types/jasmine": "2.5.41", 
    "@types/jasminewd2": "^2.0.0", 
    "jasmine": "^2.4.1", 
    "protractor": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor", 
    "typescript": "~2.0.0" 
    }, 
    "devDependencies": { 
    "@types/jasminewd2": "^2.0.0", 
    "ts-node": "^3.0.2" 
    } 
} 

spec.ts文件

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor'; 

describe('protractor with typescript typings',() => { 
    beforeEach(() => { 
    browser.get('http://www.angularjs.org'); 
    }); 

    it('should greet the named user',() => { 
    element(by.model('yourName')).sendKeys('Julie'); 
    let greeting = element(by.binding('yourName')); 
    expect(greeting.getText()).toEqual('Hello Julie!'); 
    }); 

    it('should list todos', function() { 
    let todoList = element.all(by.repeater('todo in todoList.todos')); 
    expect(todoList.count()).toEqual(2); 
    expect(todoList.get(1).getText()).toEqual('build an angular app'); 
    }); 
}); 

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es6", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "inlineSourceMap": true, 
    "declaration": false, 
    "noImplicitAny": false, 
    "outDir": "tmp" 
    }, 
    "exclude": [ 
    "node_modules", 
    "asyncAwait", 
    "plugins.ts" 
    ] 
} 
+0

您正在使用哪個nodejs版本?你也有多個'@ types/jasminewd2'模塊 –

+0

節點版本 - 6.10.3, 不知道關於多個'@ types/jasminewd2',因爲我檢查過我只有_node_modules/@ types/jasmine_文件夾。 – sunpat

+2

您發佈的package.json有多個'@ types/jasminewd2',請刪除它們也嘗試安裝最新的茉莉花類型 - 'npm install -S @ types/jasmine @ latest' –

回答

1

我有同樣的問題,我固定它執行以下操作:

1)我換成"@types/jasmine": "2.5.41""@types/jasmine": "^2.5.51""typescript": "~2.0.0""typescript": "2.1"

2)I執行npm install && npm test。我有一個新的錯誤,所以我接下來的兩個步驟。

3)I執行node_modules /的.bin/webdriver的管理器更新

4)在conf.ts註釋的線路輸出 seleniumAddress: 'http://localhost:4444/wd/hub',

5)本人執行npm test和它的工作。

相關問題