observer-spy
ng-mocks
observer-spy | ng-mocks | |
---|---|---|
1 | 9 | |
368 | 1,001 | |
0.8% | 1.3% | |
3.7 | 10.0 | |
7 months ago | 4 days ago | |
TypeScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
observer-spy
-
Angular Unit testing tools
Observer-Spy is from Shai Reznik and is indispensable when testing observables. It takes so much of the boilerplate and scariness out of testing. auto-spies is another library from Shai. This library will create spies for you from your objects. ng-mocks has become a must-have in my testing toolkit. It allows some amazing things to happen. For example, imports: [MockModule(MyModuleDependency)]. It makes testing so easy and often painless.
ng-mocks
- Angular (v15) MatStepper + Jest (v29) + ng-mocks
-
Informal AMA: Angular Signals RFC
Is the Angular team aware of NG Mocks and NG Spectator?
-
Services needed in every components unit test
No neither of those. You're unit testing the component, so you don't want any external interference. You can create a mock version of the service, I like using ng-mocks to simplify a lot of this: https://www.npmjs.com/package/ng-mocks
-
Is Unit Testing in Angular overrated?
No way, you just mock the services. Check out this library: https://www.npmjs.com/package/ng-mocks
-
Unit testing <google-map>, Export of name 'mapMarker' not found!
I recommend using MockModule from ng-mocks https://www.npmjs.com/package/ng-mocks
-
20+ JavaScript Utilities to Boost Your Productivity As a Developer
8. NG-Mocks
-
How to Mock Services in Angular
You can have a look at ng-mocks. It provides a great toolset for angular mocks.
-
Spec file "Cannot read property of 'subscribe' of undefined"
Also, for mocking, I recommend looking into ng-mocks. https://github.com/ike18t/ng-mocks It makes mocking really easy.
-
Unit testing library for Angular application
Correct. When unit testing, you want to test the unit (parent component) in isolation. To do this, you can use something like ng-mocks (my personal favorite) to create mock components. You could also use the NO_ERRORS_SCHEMA but I don't recommend this because I like to verify that my component loads w/ all of its dependencies (even if the are just mocks). If you test your parent component w/ all of its child components, then you are doing a form of integration testing. I tend to refer to it as a grey area between unit and integration testing because there are valuable tests that can be written fairly easily and cheaply that don't truly isolate parent components from their child components.
What are some alternatives?
1log-rxjs - 1log plugin for logging RxJS observables
spectator - 🦊 🚀 A Powerful Tool to Simplify Your Angular Tests
blog_mocking_settimeout_with_jest - Mocking setTimeout with Jest
jest-mock-extended - Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
auto-spies - Create automatic spies from classes
angular-testing-library - 🐙 Simple and complete Angular testing utilities that encourage good testing practices
platform - Reactive State for Angular
dayjs - ⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
hanbi - A small javascript library for stubbing and spying on methods/functions.
ts-mockito - Mocking library for TypeScript
jest - Super-fast alternative for babel-jest or ts-jest without type checking. Please use main repository for issues
javascript-testing-best-practices - 📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (July 2023)