Issue with mocha, TestBed : TypeError: Cannot read property 'assertPresent' of undefined
See original GitHub issueI’m submitting a …
[x] bug report
Current behavior When running 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:
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]
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Testing | Cannot read property 'assertPresent' of undefined at ...
This error occurred when a Jasmine test was using fakeAsync and tick. Removing fakeAsync/tick resolved this issue.
Read more >cannot read properties of undefined angular testing - You.com
Throwing and error TypeError: Cannot read properties of undefined (reading 'getModels'). Open side panel. Angular testing Cannot read property 'name' of ...
Read more >How to fix "Cannot read properties of undefined (reading ...
I want to iterate the app works perfectly, this is only a problem when running unit tests. We're using the MatDatepickerModule with a...
Read more >JavaScript — Unit Testing using Mocha and Chai - codeburst
This article will cover testing of basic function, testing of async callback functions and testing of promises with Mocha and Chai.
Read more >How To Use waitForAsync and fakeAsync with Angular Testing
When the button is clicked, the title property is set using a promise. ... import { TestBed, waitForAsync } from '@angular/core/testing'; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed it for me
The most important thing is to keep import section like it was right after “ng new myproject”. For me import ‘zone.js/dist/zone-testing’ should be at the top of all imports: