Router test results in `Unexpected value '[object Object]' exported by the module 'MockOfErrorRoutingModule'`
See original GitHub issueI 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:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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?
[deleted due to inaccuracies]