angular icon indicating copy to clipboard operation
angular copied to clipboard

Cannot use Mocha to write angular2 tests

Open dimitrikochnev opened this issue 11 years ago • 16 comments

If I use Mocha as a testing framework I'm getting the error message:

/Projects/firebase-pipes/node_modules/angular2/typings/jasmine/jasmine.d.ts(13,18): error TS2300: Duplicate identifier 'it'.
/Projects/firebase-pipes/node_modules/angular2/typings/jasmine/jasmine.d.ts(14,18): error TS2300: Duplicate identifier 'it'.
/Projects/firebase-pipes/node_modules/angular2/typings/jasmine/jasmine.d.ts(17,18): error TS2300: Duplicate identifier 'xit'.
/Projects/firebase-pipes/node_modules/angular2/typings/jasmine/jasmine.d.ts(18,18): error TS2300: Duplicate identifier 'xit'.
typings/mocha/mocha.d.ts(37,13): error TS2300: Duplicate identifier 'describe'.
typings/mocha/mocha.d.ts(38,13): error TS2300: Duplicate identifier 'xdescribe'.
typings/mocha/mocha.d.ts(43,13): error TS2300: Duplicate identifier 'it'.
typings/mocha/mocha.d.ts(44,13): error TS2300: Duplicate identifier 'xit'.

Is it necessary to propagate Angular with Jasmine typings?

https://github.com/angular/angular/blob/master/modules/angular2/manual_typings/globals-es6.d.ts#L9.

dimitrikochnev avatar Nov 19 '15 23:11 dimitrikochnev

+1, it would be nice to be able to choose between mocha and jasmine :)

dsebastien avatar Nov 22 '15 18:11 dsebastien

:+1:

manland avatar Nov 22 '15 22:11 manland

:+1 We are running Angular 1 and Angular 2 at same time, but we can not do testing at same time.

We started Angular 1 with Jasmine1 testing, and now Angular 2 has built in with Jasmine 2 testing right? It seems have same typing issue.

yizhan avatar Dec 04 '15 03:12 yizhan

@robwormald Any idea how we could move forward without having to fiddle with typings files manually? Or is this resolved by a48 or going to be with a49?

dsebastien avatar Dec 08 '15 19:12 dsebastien

@dsebastien Can you confirm that mocha plays nicely with angular 2 (I switched to jasmine)? Testing library wraps jasmine methods and in the angularconnect session @juliemr said that currently it doesn't support mocha and other testing frameworks.

dimitrikochnev avatar Dec 08 '15 19:12 dimitrikochnev

That's correct, currently, only Jasmine 2 is fully supported. I'll be working on making this more generic once testing works great with Jasmine 2.

juliemr avatar Dec 08 '15 19:12 juliemr

No I can't, I was just about to try it out. Good to know that it does not work, thanks for the info! ;-)

dsebastien avatar Dec 08 '15 19:12 dsebastien

:+1:

lacolaco avatar Jan 07 '16 01:01 lacolaco

I'm sure @juliemr will let us know when this is officially supported, but in the meantime, I've found two ways to make it work pretty well -- writeup here: http://www.codeitall.com/?p=144

japhar81 avatar Jan 22 '16 15:01 japhar81

In beta.2, this issue looks solved to me.

https://github.com/angular/angular/commit/a4b5cb837682ce61f8c07eabd7ae8c4dc3ba80a7

lacolaco avatar Jan 29 '16 17:01 lacolaco

Typings do appear fixed, but the tests still fail under mocha -- i guess that's expected :)

japhar81 avatar Jan 29 '16 18:01 japhar81

@juliemr Do you have any plans to enable to use Mocha or other testing frameworks with "angular2/testing" ?

I'll be happy if that module will separate to "angular2/testing/common" and "angualr2/testing/jasmine"

lacolaco avatar Apr 27 '16 01:04 lacolaco

This should be fairly easy to create separate adapters - basically one would need to duplicate the logic in https://github.com/angular/angular/blob/master/modules/%40angular/core/testing/testing.ts but for the specific platform one chooses. The logic is thin, so this is a pretty accessible task IMO.

wesleycho avatar Jun 08 '16 22:06 wesleycho

This is now possible in RC4.

juliemr avatar Jul 01 '16 17:07 juliemr

👌 https://github.com/angular/angular/pull/9562

jakeNiemiec avatar Jul 01 '16 20:07 jakeNiemiec

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.