Comments (8)
Are you using jest
for testing?
If not see the documentation for autospy generation
Specifically the commands for different setups and chose what you need.
angular | jest | jasmine | command |
---|---|---|---|
5 | V | schematics scuri:autospy --legacy | |
5 | V | schematics scuri:autospy --for jest --legacy | |
6 | V | ng g scuri:autospy | |
6 | V | ng g scuri:autospy --for jest | |
7 | V | ng g scuri:autospy | |
7 | V | ng g scuri:autospy --for jest | |
8 | V | ng g scuri:autospy | |
8 | V | ng g scuri:autospy --for jest |
Basically for angular 5 and below use --legacy
and for jasmine
do not add --for jest
from scuri.
yes @gparlakov , I am using jest for testing and the file is generated correctly, but inside of it, seems like the type SpyOf is not working and using a private name:
from scuri.
It looks like the typing for jest is missing.
How do you include the @types/jest
?
from scuri.
@marimendez88 hi, did you manage to work out your issue? If so let's close this issue.
from scuri.
Hi, i am trying to use scuri in my project and i am getting some compilation issue on auto-spy.ts file
can you please help on this.
from scuri.
from scuri.
Here are the details
"typescript": "~4.1.5",
from scuri.
Hey @venkatp57 I was able to reproduce the issue here -> stackblitz link
(it's a fully working example with the whole setup)
It boils down to telling typescript that we know what we are doing :)
Here's a version of autospy that works as expected on the environment you specified
/** Create an object with methods that are autoSpy-ed to use as mock dependency */
export function autoSpy<T>(obj: new (...args: any[]) => T): SpyOf<T> {
const res: SpyOf<T> = {} as any;
// turns out that in target:es2015 the methods attached to the prototype are not enumerable so Object.keys returns []. So to workaround that and keep some backwards compatibility - merge with ownPropertyNames - that disregards the enumerable property.
// the Set remove duplicate entries
const keys = new Set([
...(Object.keys(obj.prototype) as Array<keyof T>),
...(Object.getOwnPropertyNames(obj.prototype) as Array<keyof T>),
]);
keys.forEach((key) => {
if (typeof key === 'string') {
(res[key] as any) = jasmine.createSpy(key);
}
});
return res;
}
/** Keeps the types of properties of a type but assigns type of Spy to the methods */
export type SpyOf<T> = T &
Partial<{
[k in keyof T]: T[k] extends (...args: any[]) => any ? jasmine.Spy : T[k];
}>;
from scuri.
Related Issues (20)
- Delete the whole expression when removing dependencies HOT 1
- Add default Observable (EMPTY) and default Promise (new Promise()) values for dependency method spy return values.
- Lint on commit
- Handle properties with Promise or Observable HOT 1
- Handle update with a custom template without any custom functions
- Check for import of autoSpy when using --update on previously created spec file HOT 3
- Support inject function from angular
- Ensure jest specific mock returns are used
- Handle Arrays of deps
- Fix autoSpy import being added in the middle of other imports
- Fix adding multiple new lines when creating deps in setup method
- Combine TS Host with Tree
- Use FileVisitorCancelToken to stop after detected one or the other HOT 1
- Handle functions declared as const
- Allow for turning off the Typescript compilation dependent features as they take 5x or 10x more time
- Simplify the Observable property
- Update Scuri to support Typescript 5.0 and above HOT 1
- Don't update names of existing dependencies
- Mocking observable properties
- Handle Abstract class being dependend on
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 scuri.