I have several json responses (from backend) that I use in Jasmine specs, to test component and service functionality.
Recently I figured to move those responses into files in order to share data across multiple specs. However I can't find recommended location to store those files in. I saw an example, where spec fixtures are placed in assets
folder, however I believe it is a wrong place, since Angular includes assets
folder into a build.
Is there a recommended location for spec fixtures in Angular structure?
this question is highly opinionated with respect to where to put the JSON files. However, inside your tsconfig.app.json
, you can put in an exclude
key that takes an array of directory locations to exclude when building and serving your application.
I would recommend to create a new folder inside your assets folder to store all your JSON responses, and then exclude that folder in your tsconfig.app.json
Example:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
],
"exclude": [
"src/test.ts",
"src/**/*.spec.ts",
"src/assets/test-data"
]
}
Hope this helps