-
Notifications
You must be signed in to change notification settings - Fork 10
Add unit tests with jest
#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
npm install --save-dev jest @types/jest ts-jest typescript
this test is slow. but it is correct.
fix for >"The provided value 'undefined' is not a valid enum value of type CanvasTextAlign." on load. add test
remove warning
25bab89 to
ba612ca
Compare
context is only used by the NodeParserRegistry, and NodeParserRegistry is already mocked.
|
I will update this branch to pull in the merged changes from |
update to match the syntax based on committed and merged code - Joined-Forces@3c694f2
b238a8a to
6a2acbc
Compare
|
|
||
| beforeEach(() => { | ||
| let nodeParserRegistry = new NodeParserRegistry(); | ||
| parser = new GenericNodeParser(nodeParserRegistry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note for the future - currently the unit tests cannot call nodeParserRegistry.loadPlugins();, because the webpack require.context is not available inside the test.
You will get an error like:
TypeError: require.context is not a function
71 |
72 | public loadPlugins(): void {
> 73 | const pluginContext = (require as any).context('../../plugins', true, /\.plugin\.ts$/);
| ^
example:
https://github.com/Joined-Forces/klee/actions/runs/18507939361/job/52741425985?pr=8
I avoid this for now by just not calling that function inside the test.
But if we want to add tests for loadPlugins() in the future, we would need to fix this.
One possible way would be to patch and mock require.context before the tests run. This might require changing some code, as currently adding a mock in setupFiles happens too late.
But: this PR will add test coverage on a number of other areas, and we can always refactor later.
Let me know what you think.
jestas a unit testing systemHere are a number of unit tests to prove that the code from #6 works.
I have added in several null checks where I ran into crashes while creating and testing some parser classes.
There is a new class
TestableNodeControl, designed to make it easier to test your parsing classes (especially if you create your own custom parsing classes, like you can do with #7 )It gives you access to some of the node properties so you can verify e.g. if they have the icon and color that you want.
(If you are willing to accept and merge in #6 , the diff here will become a lot smaller.
You can ignore the commits before
7195288)Run the tests with: