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.

TesBed - Error to run unit test

See original GitHub issue

Hello @marcoturi !! I tried use this repo structure. The jasmine Simple test works fine, but, if I create another spec that use the TestBed angular2 class to load a component, I got the error below:

error-testbed-karma-roolup

Do you know what does mean “symbol” error ? I think that needs include zone.js library on karma.conf.js. What dou think?

See my snippet code, after change home.spec.ts file

import { HomePage } from './home';
import { TestBed } from '@angular/core/testing';

describe('Sales Service', () => {
    let fixture: any;
    let component: HomePage;

    beforeEach((done) => {

        TestBed.configureTestingModule({
            declarations: [HomePage],
        });

        fixture = TestBed.createComponent(HomePage);
        component = fixture.componentInstance;
        done();
    });

    it('should load component', (done) => {
        expect(fixture).toBeDefined();
        expect(component).toBeDefined();
        done();
    });
});

OBS: Needs perform npm install --save rxjs-es to store in package.json file. Your karma.conf.js require this 😃

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
marcoturicommented, Oct 3, 2016

https://github.com/driftyco/ionic-app-scripts/issues/51 Looks like ionic team is implementing e2e and unit tests by default (over angular cli).

2reactions
mfdevelopercommented, Oct 3, 2016

Hello guys!! @marcoturi and @NelsonBrandao, I was did these changes on files karma param, and the ‘Zone undefined error is gone’. However, I got a lot of many errors haha. But, I’ve added the minors files like your snippet @NelsonBrandao!

files: [
       'node_modules/reflect-metadata/Reflect.js',
       'node_modules/zone.js/dist/zone.js',     // Zone.js dependencies (Zone undefined)
       'node_modules/zone.js/dist/sync-test.js',
       'node_modules/zone.js/dist/proxy.js',
       'node_modules/zone.js/dist/jasmine-patch.js',
       'node_modules/zone.js/dist/async-test.js',
       'node_modules/zone.js/dist/fake-async-test.js',
       'src/**/*.spec.ts',
       { pattern: 'node_modules/reflect-metadata/Reflect.js.map', included: false, served: true }, // 404 on the same
    ]

So, I created this gist today: https://gist.github.com/mfdeveloper/d9349dea78ba34a36adc7ada56ffd0c0

There, you will find the implementations:

1 - Fix the injector of null error and platform error with this line:

//Initialize the test: prevent 'platform' undefined error
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

PS: Can be moved to a karma-shim file

2 - Remove console.log(process...) from home.ts file, to avoid process undefined error.

Now, I got the error: Uncaught SyntaxError: Unexpected token export

I think that this happens because Ionic2 has so many components/services dependencies on their flow. But, I don’t know which the dependency token is. I tried use the NO_ERRORS_SCHEMA on TestBed.configureTestingModule method (like official angular doc link: https://angular.io/docs/ts/latest/guide/testing.html#!#shallow-component-test) , but the same error is displayed for me 😦

OBS: I created this gist instead a pull request because this isn’t working by now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve unit testcase error in Angular - Stack Overflow
If you don't care about Component1 being rendered while running unit tests of Component2 , you can use schemas: [NO_ERRORS_SCHEMA].
Read more >
Unit test should fail if an element is not known #36430 - GitHub
Having errors in console with unit tests passing is not good. I use this snippet: const originalConsoleError = window.console.error; const ...
Read more >
Angular unit testing tutorial with examples - LogRocket Blog
This tutorial demonstrates how to build an Angular app and write a unit test, test an async operator, and automatically generate a unit ......
Read more >
Component testing scenarios - Angular
Error : This test module uses the component BannerComponent which is using a "templateUrl" or "styleUrls", but they were never compiled. Please call...
Read more >
Testing Services – Testing Angular
In the unit test, we replace the dependency with a fake that ... For testing Services with dependencies, we will use the TestBed...
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