glr
October 13, 2016, 2:45pm
1
Hello
I am new to meteor and would like to experiment with it using angular2 on the client-side. A have read the tutorials on the angular-meteor site and started off with the angular2-meteor-base boilerplate, which has some sample unit tests. Unfortunately, the client-side tests fail to run.
Has anyone managed to make them work?
Can you point me to a working example of unit testing an angular2-meteor project?
Thanks in advance.
There is an open issue with the angular project that discusses the issue you’re seeing when trying to run the client side tests:
opened 08:53AM - 04 Sep 16 UTC
closed 09:42PM - 26 Jan 18 UTC
area: testing
**I'm submitting a ...**
```
[x] bug report
```
**Current behavior**
When run… ning tests, I get the error:
```
> mocha build/test
ODataService -
1) "before each" hook for "Construct via injection"
0 passing (41ms)
1 failing
1) "before each" hook for "Construct via injection":
TypeError: Cannot read property 'assertPresent' of undefined
at resetFakeAsyncZone (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\@angular\core\bundles\core-testing.umd.js:385:22)
at Context.<anonymous> (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\@angular\core\bundles\core-testing.umd.js:1255:13)
at callFn (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\mocha\lib\runnable.js:334:21)
at Hook.Runnable.run (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\mocha\lib\runnable.js:327:7)
at next (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\mocha\lib\runner.js:299:10)
at Immediate.<anonymous> (C:\Users\azureuser\Documents\GitHub\_forks\angular2-odata\node_modules\mocha\lib\runner.js:327:5)
```
My test looks like:
``` ts
require('zone.js');
import 'reflect-metadata';
import { assert } from 'chai';
import { Observable, Operator } from 'rxjs/rx';
import { Location } from '@angular/common';
import { inject, TestBed } from '@angular/core/testing';
// import { TestBedHelper } from './testbedHelper';
import { MockBackend } from '@angular/http/testing';
import { BaseRequestOptions, Http, ConnectionBackend, HttpModule } from '@angular/http';
import { IEmployee } from './employee';
import { ODataOperation } from '../operation';
import { ODataServiceFactory } from '../odataservicefactory';
import { ODataConfiguration } from '../config';
describe('ODataService - ', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
BaseRequestOptions,
MockBackend,
{
provide: Http, useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
ODataConfiguration,
ODataServiceFactory
],
imports: [
HttpModule
]
});
});
it('Construct via injection', inject([ ODataServiceFactory ], (factory: ODataServiceFactory) => {
// Act
let service = factory.CreateService<IEmployee>('Employees');
// Assert
assert.isNotNull(service);
}));
});
```
**Please tell us about your environment:**
- **Mocha version:** 3.0.2
- **Angular version:** 2.0.0-rc.6
- **Language:** [all | TypeScript | ES6/7 | ES5]
One of the possible workarounds mentioned might help.