You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-39Lines changed: 54 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,48 @@
1
-
Ionic Unit Testing Example
2
-
=====================
1
+
# Ionic Unit Testing Example
3
2
4
-
This repository is an example project that gives guidance on setting up your Ionic application for unit testing and end-to-end (E2E) testing. We have been told the folks at Ionic will be adding testing features to new projects in the future. But until then, feel free to borrow from this project as needed.
3
+
**This repository is an example project that gives guidance on setting up your Ionic application for unit testing and end-to-end (E2E) testing.** We have been told the folks at Ionic will be adding testing features to new projects in the future. But until then, feel free to borrow from this project as needed.
5
4
6
5
Special thanks to all of the contributors. With the exception of the Ionic team's updates to the framework, this project is stable. If you have a suggestion, feel free to update code and make a pull request. Find a problem or bug, feel free to file a detailed issue.
7
6
7
+
## How to Configure Your Ionic Application for Testing
8
+
9
+
Read [this tutorial](https://leifwells.github.io/2017/08/27/testing-in-ionic-configure-existing-projects-for-testing/) for instructions on how to apply the testing configuration in this project to your own project.
10
+
11
+
## Mocking Classes for Ionic
12
+
When a developer unit tests a component, the objective is to isolate that component as much as possible. In the case of an Ionic page, you may have Ionic components like `NavController`, `LoadingContoller`, or `Platform`. Adding these components means adding pieces of the Ionic framework to your test, thus not isolating the component. As part of this example, the file `test-config/mocks-ionic.ts` is provided for creating simple mocks for many of the classes in Ionic that you may need. You may use the classes from this file in test files inside the `TestBed.configureComponent()` method argument's `provider` array as seen in our [example unit test file](https://github.com/ionic-team/ionic-unit-testing-example/blob/master/src/app/app.component.spec.ts).
13
+
14
+
There are other mocking options that should be mentioned:
Also worth mentioning is [ionic-native-mocks](https://github.com/chrisgriffith/ionic-native-mocks) which can be helpful when mocks for Ionic Native classes used in your project are needed.
19
+
20
+
Getting Started with this Project
21
+
-----------
22
+
23
+
To get started, clone this repo, and run `npm install` in the root directory.
@@ -15,7 +53,16 @@ Thanks to @lathonez, we now have functioning code coverage functionality. With t
15
53
16
54
The documentation is created inside the `/coverage` folder (ignored by git).
17
55
18
-
## **Also of note:**
56
+
## Looking for Version 2?
57
+
58
+
If you are using Ionic v2, please see our [ionic-v2-branch](https://github.com/ionic-team/ionic-unit-testing-example/tree/ionic-v2-branch).
59
+
60
+
## Credits
61
+
62
+
This repository is based on the awesome [unit testing example](https://github.com/roblouie/unit-testing-demo) from [@roblouie](https://github.com/roblouie/):thumbsup:
63
+
64
+
Past Updates
65
+
==========
19
66
20
67
### **2017-08-26: Update to `ionic-angular` version 3.6.0**
21
68
@@ -25,17 +72,17 @@ We updated the project to `ionic-angular` version `3.6.0`. Developers wishing to
25
72
26
73
Thanks to [@datencia](https://github.com/datencia) for providing an update to our Karma configuration that properly sets the Karma base path so that image assets can be found during testing. This fix should also work any JSON data files you might want to use for testing. He also provided an image and updated our sample unit test spec file that tests that the image is found.
27
74
28
-
## **Added: Update code to match Ionic templates**
75
+
####**Added: Update code to match Ionic templates**
29
76
30
77
Thanks (again) to [@danielsogl](https://github.com/danielsogl/) for providing a code update to the project so that our code matches code created by using the `ionic start` command. Having this code properly match is important as it provides the best practice guidance for handling application start up.
31
78
32
-
### *2017-05-28: Update to Version 3.3.0*
79
+
####*2017-05-28: Update to Version 3.3.0*
33
80
34
81
Thanks to [@danielsogl](https://github.com/danielsogl/) for getting us up-to-date with Ionic 3.3.0, Angular 4.1.2 and Ionic Native 3.10.2.
35
82
36
83
Thanks to [@johnstonbl01](https://github.com/johnstonbl01/) for adding a couple of mocks that prevent us from seeing some unnecessary warning messages.
37
84
38
-
### *2017-05-12: Update to Version 3*
85
+
####*2017-05-12: Update to Version 3*
39
86
40
87
We've updated this repo to use Ionic v3.2.1 and Ionic CLI v3.0.0.
41
88
@@ -47,35 +94,3 @@ npm remove -g ionic
47
94
npm install -g ionic
48
95
```
49
96
If you run `ionic -v` it should return `3.0.0` (or better, depending on what has been released.
50
-
51
-
Looking for Version 2?
52
-
----------------------
53
-
54
-
If you are using Ionic v2, please see our [ionic-v2-branch](https://github.com/ionic-team/ionic-unit-testing-example/tree/ionic-v2-branch).
55
-
56
-
57
-
Credits
58
-
=====================
59
-
60
-
This repository is based on the awesome [unit testing example](https://github.com/roblouie/unit-testing-demo) from [@roblouie](https://github.com/roblouie/):thumbsup:
61
-
62
-
Getting Started
63
-
===============
64
-
65
-
To get started, clone this repo, and run `npm install` in the root directory.
66
-
67
-
Unit Tests
68
-
----------
69
-
70
-
To run the tests, run `npm test`.
71
-
72
-
See the example test in `src/app/app.component.spec.ts` for an example of a component test.
73
-
74
-
End-To-End Tests (Browser-Only)
75
-
-------------------------------
76
-
77
-
To serve the app, run `ionic serve`.
78
-
79
-
To run the end-to-end tests, run (while the app is being served) `npm run e2e`.
80
-
81
-
See the example end-to-end test in `e2e/app.e2e-spec.ts`.
0 commit comments