This repository was archived by the owner on Sep 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +73
-7
lines changed Expand file tree Collapse file tree 5 files changed +73
-7
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # Service
2+ > Testing recipes for Services
3+
4+ ## Table of contents
5+
6+ - [ Boilerplate] ( #boilerplate )
7+ - [ Exposed properties] ( #expose-properties )
8+ - [ Exposed methods] ( #expose-methods )
9+ - [ Methods from other services] ( #methods-from-other-services )
10+ - [ $http] ( $http )
11+ - [ Promises] ( #promises )
12+
13+ ## Boilerplate
14+
15+ Before start we need to initialize the service and mock it's dependencies in our tests:
16+
17+ ``` js
18+ describe (' SampleService' , function () {
19+ ' use strict' ;
20+
21+ var sampleService;
22+
23+ beforeEach (module (' myApp' ));
24+
25+ beforeEach (inject (function (_sampleService_ ) {
26+ sampleService = _sampleService_;
27+ }));
28+
29+ ...
30+ });
31+ ```
32+
33+
Original file line number Diff line number Diff line change 1+ ( function ( ) {
2+ 'use strict' ;
3+
4+ angular . module ( 'myApp' )
5+ . factory ( 'sampleService' , SampleService ) ;
6+
7+ function SampleService ( ) {
8+ var service = {
9+ foo : 'bar' ,
10+ bar : bar
11+ } ;
12+
13+ return service ;
14+
15+ function bar ( ) {
16+ service . foo = 'baz' ;
17+ }
18+ }
19+
20+ } ( ) ) ;
Original file line number Diff line number Diff line change 1+ describe ( 'SampleService' , function ( ) {
2+ 'use strict' ;
3+
4+ var sampleService ;
5+
6+ beforeEach ( module ( 'myApp' ) ) ;
7+
8+ beforeEach ( inject ( function ( _sampleService_ ) {
9+ sampleService = _sampleService_ ;
10+ } ) ) ;
11+
12+ it ( 'should expose a property' , function ( ) {
13+ expect ( sampleService . foo ) . toBe ( 'bar' ) ;
14+ } ) ;
15+
16+ it ( 'should expose a method' , function ( ) {
17+ sampleService . bar ( ) ;
18+ expect ( sampleService . foo ) . toBe ( 'baz' ) ;
19+ } ) ;
20+ } ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments