Skip to content

fix: custom matchers are not available when using createHttpFactory()#736

Merged
NetanelBasal merged 1 commit intongneat:masterfrom
xemlock:master
Nov 2, 2025
Merged

fix: custom matchers are not available when using createHttpFactory()#736
NetanelBasal merged 1 commit intongneat:masterfrom
xemlock:master

Conversation

@xemlock
Copy link
Contributor

@xemlock xemlock commented Nov 1, 2025

Custom matchers are not available when using createHttpFactory().

It may have been a deliberate decision to add custom matchers only to DOM-related contexts ( component, directive, host or pipe), but:

  • they are available with createServiceFactory(), which does not necessary imply using components or DOM
  • documentation doesn't say that these matchers are not available in some contexts, making errors like:
    TypeError: expect(...).toHaveProperty is not a function
    
    quite unexpected to the developer. Especially when it happens in some tests, and not in others.

Some matchers are not necessarily DOM-only, and could be used in more general contexts, for example toHaveProperty(). Also,

expect(obj).toHaveProperty('foo');

is definitely much better developer experience than:

expect(obj).toEqual(jasmine.ObjectContaining({ 'foo': jasmine.anything() }));

And better DX is what Spectator is all about.

So, for consistency, it would be nice to have custom matchers available regardless of the factory being used, which includes tests using createHttpFactory. Which this Pull Request is attempting to solve.


PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix (kind of?)
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

TypeError: expect(...).toHaveProperty is not a function in tests using createHttpFactory. The error doesn't occur in tests using other factory functions (e.g., createServiceFactory).

Issue Number: N/A

What is the new behavior?

Custom matchers are available in tests using createHttpFactory.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@NetanelBasal NetanelBasal merged commit bbf63eb into ngneat:master Nov 2, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants