@@ -64,99 +64,14 @@ beforeEach(function() {
64
64
bindJQuery ( ) ;
65
65
jqLite ( document . body ) . html ( '' ) ;
66
66
67
- function cssMatcher ( presentClasses , absentClasses ) {
68
- return function ( ) {
69
- var element = jqLite ( this . actual ) ;
70
- var present = true ;
71
- var absent = false ;
72
-
73
- forEach ( presentClasses . split ( ' ' ) , function ( className ) {
74
- present = present && element . hasClass ( className ) ;
75
- } ) ;
76
-
77
- forEach ( absentClasses . split ( ' ' ) , function ( className ) {
78
- absent = absent || element . hasClass ( className ) ;
79
- } ) ;
80
-
81
- this . message = function ( ) {
82
- return "Expected to have " + presentClasses +
83
- ( absentClasses ? ( " and not have " + absentClasses + "" ) : "" ) +
84
- " but had " + element [ 0 ] . className + "." ;
85
- } ;
86
- return present && ! absent ;
87
- } ;
88
- }
89
-
90
67
this . addMatchers ( {
91
- toBeInvalid : cssMatcher ( 'ng-invalid' , 'ng-valid' ) ,
92
- toBeValid : cssMatcher ( 'ng-valid' , 'ng-invalid' ) ,
93
- toBeDirty : cssMatcher ( 'ng-dirty' , 'ng-pristine' ) ,
94
- toBePristine : cssMatcher ( 'ng-pristine' , 'ng-dirty' ) ,
95
-
96
- toEqualData : function ( expected ) {
97
- return equals ( this . actual , expected ) ;
98
- } ,
99
-
100
68
toHaveClass : function ( clazz ) {
101
69
this . message = function ( ) {
102
70
return "Expected '" + sortedHtml ( this . actual ) + "' to have class '" + clazz + "'." ;
103
71
} ;
104
72
return this . actual . hasClass ?
105
73
this . actual . hasClass ( clazz ) :
106
74
jqLite ( this . actual ) . hasClass ( clazz ) ;
107
- } ,
108
-
109
- toEqualError : function ( message ) {
110
- this . message = function ( ) {
111
- var expected ;
112
- if ( this . actual . message && this . actual . name == 'Error' ) {
113
- expected = toJson ( this . actual . message ) ;
114
- } else {
115
- expected = toJson ( this . actual ) ;
116
- }
117
- return "Expected " + expected + " to be an Error with message " + toJson ( message ) ;
118
- } ;
119
- return this . actual . name == 'Error' && this . actual . message == message ;
120
- } ,
121
-
122
- toMatchError : function ( messageRegexp ) {
123
- this . message = function ( ) {
124
- var expected ;
125
- if ( this . actual . message && this . actual . name == 'Error' ) {
126
- expected = toJson ( this . actual . message ) ;
127
- } else {
128
- expected = toJson ( this . actual ) ;
129
- }
130
- return "Expected " + expected + " to match an Error with message " + toJson ( messageRegexp ) ;
131
- } ;
132
- return this . actual . name == 'Error' && messageRegexp . test ( this . actual . message ) ;
133
- } ,
134
-
135
- toHaveBeenCalledOnce : function ( ) {
136
- if ( arguments . length > 0 ) {
137
- throw new Error ( 'toHaveBeenCalledOnce does not take arguments, use toHaveBeenCalledWith' ) ;
138
- }
139
-
140
- if ( ! jasmine . isSpy ( this . actual ) ) {
141
- throw new Error ( 'Expected a spy, but got ' + jasmine . pp ( this . actual ) + '.' ) ;
142
- }
143
-
144
- this . message = function ( ) {
145
- var msg = 'Expected spy ' + this . actual . identity + ' to have been called once, but was ' ,
146
- count = this . actual . callCount ;
147
- return [
148
- count == 0 ? msg + 'never called.'
149
- : msg + 'called ' + count + ' times.' ,
150
- msg . replace ( 'to have' , 'not to have' ) + 'called once.'
151
- ] ;
152
- } ;
153
-
154
- return this . actual . callCount == 1 ;
155
- } ,
156
-
157
-
158
- toBeOneOf : function ( ) {
159
- return angularArray . indexOf ( arguments , this . actual ) !== - 1 ;
160
75
}
161
76
} ) ;
162
77
@@ -344,6 +259,7 @@ function sortedHtml(element, showNgClass) {
344
259
}
345
260
346
261
262
+ // TODO(vojta): migrate these helpers into jasmine matchers
347
263
/**
348
264
* This method is a cheap way of testing if css for a given node is not set to 'none'. It doesn't
349
265
* actually test if an element is displayed by the browser. Be aware!!!
0 commit comments