Reputation: 681
I have a simple Angular library for internal use with some pipes and directives, the library is used in several projects. When the developers need to write the unit testing, they are creating a stub file for the pipe. They have the same stub in 5 projects duplicate always the same code.
What I want to do is provide this stub file for the pipe or directive, something similar to what does the RouterTestingModule
, including a test module or include the stub itself inside my library, but I don't have any clue of how to do it.
Should I have to create a LibraryTestingModule
and include it inside the main public_api
and also include it in LibraryModule
, that make sense?
Upvotes: 1
Views: 517
Reputation: 681
My workaround to solve this was the following:
At the same level of src
path, create a testing
folder. Inside it include the next files
/src
/testing
┣ /src
┃ ┣ /stubs // my testing files here
┃ ┗ index.ts
┣ index.ts // barrel file
┣ package.json
┣ public_api.ts // similar to index.ts, entry point for public API of the package
┗ library-testing.module.ts // Angular module
For me, this was the trick, including the following lines inside the package.json
{
"ngPackage": {
"lib": {
"entryFile": "public_api.ts",
}
}
}
And with all these, now I can use my-lib/some-pipe.ts
and in testing files, now I have access to my-lib/testing/some-stub-pipe.ts
.
Upvotes: 1