NativeScript - how to get unit tests to work properly?
See original GitHub issueI’m writing an app with NativeScript 6+ and Angular 8+.
I’m trying to write some unit tests and get them up and running.
I have read the documentation on unit testing: https://docs.nativescript.org/tooling/testing/testing
I followed the directions there for setting up the tests and using TestBed. My tests are not working and throwing errors.
Here is my repository: https://github.com/aubrey-fowler/NativeScriptUnitTests
Questions:
- The documentation only shows an example of how to write a test for a component. How do I write a test for a service? I also need to use TestBed for this because my service has dependency injection.
- My tests are throwing errors. Why and how can I fix them?
Errors:
no reachable hosts
on my Android phone
code snippet:
import { ItemsComponent } from '../app/item/items.component';
import {
nsTestBedAfterEach,
nsTestBedBeforeEach,
nsTestBedRender
} from 'nativescript-angular/testing';
describe('ItemsComponent Test', () => {
beforeEach(nsTestBedBeforeEach([ItemsComponent]));
afterEach(nsTestBedAfterEach(false));
it('should be defined', () => {
nsTestBedRender(ItemsComponent).then((fixture) => {
fixture.detectChanges();
const component = fixture.componentInstance;
expect(component).toBeTruthy;
});
});
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Unit Testing - NativeScript Docs
Write and execute unit tests to ensure that newly added features are working correctly and no regressions are introduced in the mobile app....
Read more >NativeScript - how to get unit tests to work properly?
The documentation only shows an example of how to write a test for a component. How do I write a test for a...
Read more >NativeScript - Testing - Tutorialspoint
Unit testing is the easiest method to test an application. It is based on ensuring the correctness of a piece of code (a...
Read more >Unit Testing For NativeScript - YouTube
Lets discuss how you can take your really cool app; and make sure it continues to work after you make bug fixes and...
Read more >Adding Unit Tests to Your NativeScript App
Enter the unit test. Unit testing has us write tests, in code, to test the smallest pieces of our apps. In theory, as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the repo @aubrey-fowler - we’ll take a look!
@NathanWalker doesnt work either:
To reproduce:
Sadly my project runs into the exact same issues about setting up the UnitTests, thats why its impossible to use them at the moment, which is pretty bad because some stuff needs to be covered with it…