question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper message when angular test.ts has invalid order instead of "TypeError: Cannot read property 'assertPresent' of undefined"

See original GitHub issue

After I enabled ts-lint autofix with import sorting I got error in my tests “TypeError: Cannot read property ‘assertPresent’ of undefined”

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import 'zone.js/dist/zone-testing';


declare const require: any;

getTestBed().initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
);
const context = require.context('./', true, /\.spec\.ts$/);

context.keys().map(context);

After that i found https://github.com/angular/angular/issues/11317#issuecomment-419122951 which solved my issue but I am not one who have this problem

I would expect to see proper message that my “import ‘zone.js/dist/zone-testing’;” is wrong.

I also submitted feature-request to angular-cli but it was rejected. Such issues just make people to dislike angular while I want them to love it 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
JiaLiPassioncommented, Oct 19, 2018

the reason is tslint just change the import order. you need to import 'zone.js/dist/zone-testing' in the first line.

1reaction
JiaLiPassioncommented, Oct 19, 2018

@vovikdrg, oh, you are right, I will change this message, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing | Cannot read property 'assertPresent' of undefined at ...
PS: I am using VS Code, which now automatically sorts imports upon file save and thus changes my custom order of imports, which...
Read more >
Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
TestBed - Angular
Configures and initializes environment for unit testing and provides methods for creating components and services in unit tests.
Read more >
How To Use waitForAsync and fakeAsync with Angular Testing
Learn how to test asynchronous code more easily using the async ... When the button is clicked, the title property is set using...
Read more >
How to fix "Cannot read properties of undefined (reading ...
I don't have a good answer for this one... I'm getting an error like this from an Angular unit tests: TypeError: Cannot read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found