Comments (6)
Sorry for the late response.
Please provide your test .ts file and your command output.
I think you are missing something related to mock.
from ngentest.
Command - ngentest data.service.ts
data.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
@Injectable()
export class DataService {
constructor(private _router: Router) {
}
}
data.service.spec.ts
import { async } from '@angular/core/testing';
import { Injectable } from '@angular/core';
import { Observable, of as observableOf, throwError } from 'rxjs';
import { DataService } from './menu.service';
import { Router } from '@angular/router';
@Injectable()
class MockRouter {
navigate() {};
}
describe('DataService', () => {
let service;
beforeEach(() => {
service = new DataService({}); // ERROR: Argument of type '{}' is not assignable to parameter of type 'Router'. Type '{}' is missing the following properties from type 'Router': rootComponentType, urlSerializer, rootContexts, location, and 48 more.
});
});
from ngentest.
This is working for me. if this is from your Typescript checking, please make the type checking loose for your .spec files
$ cat ./data.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
@Injectable()
export class DataService {
constructor(private _router: Router) {
}
test() {
this.foo = 1;
}
}
$ cat ./data.service.spec.ts
import { async } from '@angular/core/testing';
import { Injectable } from '@angular/core';
import { Observable, of as observableOf, throwError } from 'rxjs';
import { DataService } from './data.service';
import { Router } from '@angular/router';
@Injectable()
class MockRouter {
navigate = jest.fn();
}
describe('DataService', () => {
let service;
beforeEach(() => {
service = new DataService({});
});
it('should run #test()', async () => {
service.test();
});
});
$ jest ./data.service.spec.ts
PASS ./data.service.spec.ts
DataService
✓ should run #test() (2ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.382s, estimated 4s
Ran all test suites matching /.\/data.service.spec.ts/i.
jest-html-reporter >> Report generated (./reports/unit-test-report/index.html)
from ngentest.
Hi,
After adding the line // @ts-ignore
above the error line seems to make the error go away and makes the test runs smoothly.
Also, can you test it in Karma once?
Thanks.
from ngentest.
This is tsconfig.json
example to ignore spec files.
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@angular/*": [
"./node_modules/@angular/*"
],
"test/*": [
"test/*"
]
},
"outDir": "./dist/out-tsc",
"sourceMap": true,
"allowJs": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"preset": "ts-jest"
}
By adding exclude
block, you can simply ignore all .spec typescript checking.
"exclude": [
"node_modules",
"**/*.spec.ts"
],
Regarding Karma, I cannot provide test now.
from ngentest.
Thanks for the resolution, It is working fine.
from ngentest.
Related Issues (20)
- does not work with nrwl nx HOT 1
- Type error on get command help HOT 1
- In my case it failer because the model. HOT 4
- Error generating for require-from-string HOT 7
- Error generating for close method HOT 2
- cannot find module using alias HOT 5
- Explain how to deal with paths and modules HOT 2
- Invalid typescript file - have tried the solutions in the closed issue HOT 8
- if components refer to class definitions : ngentest fails
- Getting error when trying to generate unit test HOT 15
- No Support for Arrow Functions? HOT 3
- ReferenceError: HTMLElement is not defined HOT 1
- Add support of Angular 15 HOT 1
- Plugin is not working with NX15 HOT 1
- Invalid typescript file error with latest ngentest version in angular 15 HOT 7
- Bugs on new versions HOT 1
- Framework Options not supported if we use the package directly in our code HOT 1
- Cannot find module '•/ejs-templates/class.template.js' HOT 1
- [QUESTION] How to mock properly
- Angular 18 support? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngentest.