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.

Router test results in `Unexpected value '[object Object]' exported by the module 'MockOfErrorRoutingModule'`

See original GitHub issue

I tried to follow the example here

however, it doesn’t work on my end, even after I simplified the component to the simplest form with Router:

Simplified code snippet as follows:

html:

<div></div>

component:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
    selector: 'app-test',
    templateUrl: './test.component.html',
    styleUrls: ['./test.component.scss'],
})
export class TestComponent implements OnInit {
    constructor(private route: Router) {}

    ngOnInit(): void {
        console.log(this.route.url);
    }
}

spec:

import { Shallow } from 'shallow-render';

import { TestModule } from 'app/test.module';
import { TestComponent } from './test.component';

fdescribe('TestComponent', () => {
    let shallow: Shallow<TestComponent>;

    beforeEach(() => {
        shallow = new Shallow(TestComponent, TestModule);
    });

    it('should render page', async () => {
        const { find } = await shallow.render();
        expect(find('div')).toBeTruthy();
    });
});

i’m using "shallow-render": "^8.0.4", and do have the following line in test.ts:

const routes: Routes = [
    { path: '**', component: class DummyComponent {} },
];
Shallow.neverMock(HAMMER_GESTURE_CONFIG)
    .alwaysProvide(SomeService)
    .alwaysReplaceModule(RouterModule, RouterTestingModule.withRoutes(routes));

error:

	Error: Unexpected value '[object Object]' exported by the module 'MockOfErrorRoutingModule'
	error properties: Object({ ngSyntaxError: true })
	    at syntaxError (http://localhost:9876/_karma_webpack_/vendor.js:36465:17)
	    at http://localhost:9876/_karma_webpack_/vendor.js:52693:40
	    at <Jasmine>
	    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (http://localhost:9876/_karma_webpack_/vendor.js:52691:49)
	    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleSummary (http://localhost:9876/_karma_webpack_/vendor.js:52589:35)
	    at http://localhost:9876/_karma_webpack_/vendor.js:52676:55
	    at <Jasmine>
	    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (http://localhost:9876/_karma_webpack_/vendor.js:52654:49)
	    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (http://localhost:9876/_karma_webpack_/vendor.js:60043:51)
	    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndAllComponents (http://localhost:9876/_karma_webpack_/vendor.js:60031:36)
HeadlessChrome 74.0.3729 (Mac OS X 10.14.2)

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
getsafcommented, May 17, 2019

Looks like you found a legit bug in shallow-render. Glad you reported it, I have a PR up that should fix it. @kreatemore want to give that PR a review?

2reactions
getsafcommented, May 19, 2019

[deleted due to inaccuracies]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected value '[object Object]' imported by the module ...
Trying to add routing and move translateModule from declarations to imports (two answers i found) but this doesn't help. angular · testing.
Read more >
Unit testing Angular components - LinkedIn
You will get this error message: Error: Unexpected value '[object Object]' declared by the module 'DynamicTestModule'.
Read more >
NG0301: Export not found! - Angular
For example, if the export not found is ngForm , we need to import FormsModule and declare it in the list of imports...
Read more >
Angular 2 Unit Testing Errors & Solutions - marclloyd.co.uk
Failed : Unexpected value '[object Object]' declared by the module 'DynamicTestModule'. Fix: Import your routing file.
Read more >
Unexpected value 'undefined' declared by the module ... - Reddit
I've been running into this issue while trying to set up jest testing in an application. I have my test set up with...
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