PU-001: Feature Request To Test Functions Creators#9
Merged
Conversation
- Allow executions field in function tests (not just class tests) - Skip return value assertion when executions is present and out is omitted - Add test cases for factory functions (createStore, createCounter) - Update documentation with factory function testing section - Maintain backward compatibility for existing tests This enables testing of factory functions and builder patterns that return objects with methods, addressing the common JavaScript pattern where functions create and return objects with behavior.
- Return value assertion now depends on whether 'out' field is present in the test case, not on whether 'executions' exists - When 'out' field is omitted: function is called but return value is not asserted - When 'out:' is present (even empty): return value is asserted (empty = null in YAML) - Fixed utils.js to only add 'out' property when present in YAML - Updated mockResolver to handle simple mock definitions (fn: true) - Added comprehensive tests demonstrating the behavior - Updated documentation to clarify the behavior This allows more flexible testing where you can: - Test factory functions without asserting their return value - Explicitly assert null/undefined returns when needed - Skip return assertions for any function test
- Added special keyword __undefined__ to assert undefined return values - Handles __undefined__ in all assertion contexts: - Function return values (out: __undefined__) - Method return values in executions - Mock return values and input expectations - Property assertions - Added comprehensive tests demonstrating the functionality - Updated documentation with examples This solves the limitation where YAML cannot represent JavaScript undefined: - `out:` in YAML becomes null - `out: undefined` in YAML becomes the string "undefined" - `out: __undefined__` now properly asserts undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
executionsfield in function tests (previously only available for class tests)executionsis present andoutis omittedImplementation Details
This PR implements the feature request to support testing functions that return objects with methods (factory pattern). The key changes are:
executionsfield for function testsoutis explicitly providedTest Plan
examples/store.test.yamlwith comprehensive test casesexamples/store.jswith two factory functions (createStoreandcreateCounter)outis omittedDocumentation
Backward Compatibility
This change is fully backward compatible. Existing tests continue to work as before, and the new functionality is only activated when
executionsis used in a function test.